简体   繁体   中英

How to use GetArray() from an unnamed JsonObject

If JSON is in this format:

{
metrics: [
    {
         "id":1,
         "name":"foo"
    },
    {
          "id":2,
          "name":"bar"
    }
]
}

I can use:

JsonArray jsonArray = jsonObject["metrics"].GetArray();

Now, if my JSON consists of an unnamed array like:

[
 {
    "id":1,
    "name":"foo"
 },
 {
    "id":2,
    "name":"bar"
 }
]

how can I get the jsonArray ?

You should be able to parse it directly:

string jsonString = "[ { "id": 1, "name": "foo" }, { "id": 2, "name":"bar" } ]";
JsonArray jsonArray = JsonArray.Parse(jsonString);

So no need to use JsonObject .

试试JsonArray.Parse(...)方法......

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