Following paragraph JSON:
[{
"ID": "01",
"text": "a"
},
{
"ID": "02",
"text": "two"
}]
analytic use is: JObject jsonF = ( JObject) JsonConvert.DeserializeObject (jsonS)
of this code, then how to take value take?
If the [[preceded { "result" :,} I will add the final use jsonF [ "result"] [0 ] [ "text"]. ToString () to get value]
codes result in the absence of how you should change?
Use under 标 preparative index.
jsonF[0]["text"].ToString()
json should be not only the key value does not exist now.
Json string you should be given a json array type.
JArray jsonF = (JArray)JsonConvert.DeserializeObject(jsonS)
JArray jsonF = JsonConvert.DeserializeObject<JArray>(jsonS)
First you have json outside [] is an array that he received when you have two ways.
The first is to establish the best way to this class.
Public class the Model
{
public String ID {GET; SET;}
public String text { GET; SET;}
}
then
var list = new JsonConvert.DeserializeObject <List < Model >> (json);
wanted value
var text = list [0] .text; to.
If you do not want to build this object. Then you can use
var jar =(JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
This attribute is that you need to know.
So the value to use
var text=jar [0]["text"].ToString();
The value can be .. but above the recommended method.
No key is also called json it? Do not id0. Id1 improper key
In many cases, we do not want to define so many classes to receive different json returned interface, but with Dictionary and felt the trouble to use, so this time anonymous bee forum posting machine objects will be useful