一、JObject.Parse
1.把整个json文件字符串转化成JObject格式。
JObject jsonData = JObject.Parse(jsonString);
2.逐级转换成JObject
最低级是"Device": "Windowsr",字典。
jsonData = JObject.Parse(jsonData[jsonName][jsonIndex].ToString());
3.JObject读取字典value
a.类型为value为string
if (jsonData[lastArryItem].Type == JTokenType.String){itemStringList.Add(jsonData[lastArryItem].ToString());}
b.value字符串数组类型
"selecte": ["aaa","bbb","ccc","dddd","eeee","Exit"]
if (jsonData[lastArryItem].Type == JTokenType.Array)
{//已经确定其中一个JArray jsonDataArray = (JArray)jsonData[jsonName];itemStringList.Add(jsonDataArray[jsonIndex].ToString());// 强制转换字符串保存,复杂类型会出现带{}JArray jsonDataArray = (JArray)jsonData[lastArryItem];foreach (var jsonItem in jsonDataArray){itemStringList.Add(jsonItem.ToString());}}
c.value 为objcet类型
"configure":
[{"Device": "Windows"},{"2nd Device": "DVD"}
]
foreach (JToken jdata in jsnListArray){if (jdata.Type == JTokenType.String){jsonDataList.add(jdata.ToString());}if (jdata.Type == JTokenType.Object){//转换JObject jodata = (JObject)jdata;IEnumerable<JProperty> properties = jodata.Properties();foreach (JProperty item in properties){//获取key name.jsonDataList.add(item.Name);}}}