1. Reference The namespace system. Web. Script. serialization (you need to add. Net to reference system. Web. extension. dll). 2. Define a JSON-compliant tree structure object. For example, the JSON string format returned by the server is as follows :{
"Method": "getimagefullpathlist ",
"Imgpathlist ":{
"Imgpathlist ":[
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/05/02/-5-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/01/02/-1-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/03/02/-3-201202180258330682-0004916.jpg ",
"Http: // 10.9.34.207/imagedata/image/normalimage // 2012/02/18/0 A/02/-a-201202180258330682-0004916.jpg"
]
}
} The build object is as follows:
public class ImageFullPathList
{
public string method;
public innerImgPathList imgPathList;
}
public class innerImgPathList
{
public string[] imgPathList;
}
3. Use the following statement to match the JSON string returned by the server to a custom struct. Jsonstr is the JSON string returned by the server.
JavaScriptSerializer serializer = new JavaScriptSerializer();
ImageFullPathList json = serializer.Deserialize<ImageFullPathList>(jsonStr);