Third-party components jayrock and jayrock. JSON are used to first introduce the namespace using jayrock. JSON;
Create a jsonobject.
The procedure is as follows:
String strjsontext = @ "{" cachecount ": 1," Count ":" 34 "," slice ":" 5, 5 "," list ": [1001598,1001601, 1001605, 1001609, 1001612], "page": 1, "error": 200 }";
Jsonreader reader = new jsontextreader (New stringreader (strjsontext ));
Jsonobject jsonobj = new jsonobject (); jsonobj. Import (Reader );
In this way, the JSON data of a text is converted into an object. To obtain the value of Count, you can use string COUNT = jsonobj ["count"]. tostring (); but there is a problem: list is an array. How can I get it? Don't worry. jayrock is ready for us.
Using (jsontextreader textreader = new jsontextreader (New stringreader (jsonobj ["list"]. tostring ())))
{While (textreader. Read ())
{
If (! String. isnullorempty (textreader. Text ))
{
Response. Write (textreader. Text );
}
}
}
Assign the content of the array to a jsontextreader object and use the read method to read data row by row. Of course, you can also use the jsonarray object.