Newtonsoft.Json 怎么通过数字索引取得项目
Newtonsoft.Json 如何通过数字索引取得项目?
请教,如何能够通过数字索引的方式,取得对应的值? 谢谢。
------解决方案--------------------
var dict = json.Children().OfType<JProperty>().Select((x, i) => new { x = x.Value, i }).ToDictionary(x => x.i, x => x.x);
Debug.WriteLine(dict[0].ToString());
------解决方案--------------------
string jdata="{'a':'aaa','b':'bbb','c':'ccc'}";
JObject json = JsonConvert.DeserializeObject(jdata) as JObject;
Debug.WriteLine(json["a"].ToString());//这句代码没问题
Debug.WriteLine(json[0].ToString());//这样就总是出错了。
请教,如何能够通过数字索引的方式,取得对应的值? 谢谢。
json
------解决方案--------------------
var dict = json.Children().OfType<JProperty>().Select((x, i) => new { x = x.Value, i }).ToDictionary(x => x.i, x => x.x);
Debug.WriteLine(dict[0].ToString());
------解决方案--------------------
string jdata="{'a':'aaa','b':'bbb','c':'ccc'}";
JObject jo = JObject.Parse(jdata);
string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray();
MessageBox.Show(values[0].ToString()+" "+ values[1].ToString()+" "+values[2].ToString());