简体   繁体   中英

How should I parse this json response in c#?

I'm a bit new to json responses. I've been using json.net to parse my responses into custom object. But I get the feeling that this response is a standard format that I should be able to parse easily.

Here a sample of the response.

 {"jquery": 
[
    [0, 1, "call", ["body"]], 
    [1, 2, "attr", "find"], 
    [2, 3, "call", [".status"]], 
    [3, 4, "attr", "hide"], 
    [4, 5, "call", []], 
    [5, 6, "attr", "html"], 
    [6, 7, "call", [""]], 
    [7, 8, "attr", "end"], 
    [8, 9, "call", []], 
    [0, 10, "call", ["body"]], 
    [10, 11, "attr", "captcha"], 
    [11, 12, "call", ["uIP22Wow9xa68aLQ0tl1e9Uiiinracdj"]]
]}

Is this something standard or should I just go ahead with my custom object?

Thanks

.NET 4.5 includes a JavaScriptSerializer Class which makes it easy to parse just about anything.

I usually parse my data doing something like this..

private struct MyStruct
{
  public System.Collections.ArrayList jquery { get; set; }
}

string testJson = "{\"jquery\": [[0, 1, \"call\", [\"body\"]], [1, 2, \"attr\", \"find\"], [2, 3, \"call\", [\".status\"]], [3, 4, \"attr\", \"hide\"], [4, 5, \"call\", []], [5, 6, \"attr\", \"html\"], [6, 7, \"call\", [\"\"]], [7, 8, \"attr\", \"end\"], [8, 9, \"call\", []], [0, 10, \"call\", [\"body\"]], [10, 11, \"attr\", \"captcha\"], [11, 12, \"call\", [\"uIP22Wow9xa68aLQ0tl1e9Uiiinracdj\"]]]}";
MyStruct generic = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<MyStruct>(testJson);

在此处输入图片说明

This is well-formed JSON, with one object named "jquery" . Its value is an array, each element of that array is an array again. The inner array contains several values: two numbers, then a string and lastly a string or an array of a single string.

There is nothing to suggest if any other object named "jquery" would have the same structure.

A generic JsonObject seems to be the only useful structure to parse this, in absence of any additional schema information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM