First, convert the json string into a JObject object:
JObject jo = (JObject)(CurrentSelectedItemReq);
This JObject is a "value pair" type, for example, our json string is like this:
{ "rows":[ [ {"NumIid":"001"}, {"PicUrl":""}, {"Title":"xxxxx"}, {"Price":"xxx"}, {"OuterId":"xxxx"} ], [ {"NumIid":"002"}, {"PicUrl":""}, {"Title":"xxxxx"}, {"Price":"xxx"}, {"OuterId":"xxxx"} ], [ {"NumIid":"003"}, {"PicUrl":""}, {"Title":"xxxxx"}, {"Price":"xxx"}, {"OuterId":"xxxx"} ] ] }
Then jo["rows"] is an array. If this is the opposite, if it is not an array, it may be an object, then we cast it based on what value it is actually.
Take the above json string as an example, we get this array like this:
JArray arr = (JArray)jo["rows"];
We found that this array is still an array, and the inner layer array is an object, so we can take it like this:
for (int i = 0; i < ; i++) { JArray arr2 = (JArray)arr[i]; for (int j = 0; j < ; j++) { JObject obj = (JObject)arr2[j]; (obj["NumIid"]); (); } }
If it is actually an array, we cast it with JArray, and if it is actually a value pair, we cast it with JObject.
The last layer should be an object of a value pair type. How to get all these values out?
Finally, it should be like:
{"NumIid":"003"}
The value is very simple, directly:
string str=obj["NumIid"];
The problem is that sometimes this obj looks like this:
{"PicUrl":""}
And you don't know when and what he is.
This should be done as follows:
foreach (KeyValuePair<string, JToken> kp in obj) { (); ("="); (); (); }
The above method of converting json strings into objects using Newtonsoft (detailed explanation) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.