재우니의 블로그

Newtonsoft.Json.Linq.JArray 를 통해 json 문자열을 array 형태로 담아 이를 parse 파싱도 할 수 있습니다.

 

http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JArray.htm

 

private static void Main(string[] args)
{
    var json = "[\".Net\", \"Core\", \"ASP.NET\",\"홍길동\",\"1\"]";            
    var jArray = JArray.Parse(json);

    foreach (var item in jArray.Children())
    {
        Console.WriteLine(item.Value<string>().ToString());
    }

    Console.WriteLine(String.Join(",", jArray.Select(i => i.ToString())));

    Console.ReadKey();

}

 


JArray jArray = JArray.Parse(@"[
{
  "name": "Croke Park II",
  "url": "http://twitter.com/search?q=%22Croke+Park+II%22",
  "promoted_content": null,
  "query": ""%22Croke+Park+II%22",
  "events": null
},
{
  "name": "Siptu",
  "url": "http://twitter.com/search?q=Siptu",
  "promoted_content": null,
  "query": "Siptu",
  "events": null
}]");
foreach (JObject item in jArray)
{
    string name = item.GetValue("name").ToString();
    string url = item.GetValue("url").ToString();
    // ...
}

 


 

var str = @"[1, 2, 3]";
var jArray = JArray.Parse(str);
Console.WriteLine(String.Join("-", jArray.Where(i => (int)i > 1).Select(i => i.ToString())));

 

 

stackoverflow.com/questions/16045569/how-to-access-elements-of-a-jarray-or-iterate-over-them

 

How to access elements of a JArray (or iterate over them)

I have the following Json gotten from Twitter + token {[ { "trends": [ { "name": "Croke Park II", "url": "http://twitter.com/search?q=%22Croke+Park+II%22", ...

stackoverflow.com