简体   繁体   中英

Convert string array into JSON object?

I got json[] from UI. I have to convert it into Json object how can I convert it with gson . An object which is received is like that:

 [{"name":"name","value":"value"},{"name":"first","value":"100"},{"name":"hor","value":"95"},{"name":"conf","value":"95"}],[{"name":"vaRType","value":"INCRE"},{"name":"per","value":"100"},{"name":"hor","value":"95"},{"name":"conf","value":"95"}]

I used JsonObject obj = new JsoParser().parse(jsonStrnig).getAsJsonObject(); but it throws an exception.

因为它不是有效的json对象。

Your JSON should be the following as currently it's invalid...

[
    [
        {
            "name": "name",
            "value": "value"
        },
        {
            "name": "first",
            "value": "100"
        },
        {
            "name": "hor",
            "value": "95"
        },
        {
            "name": "conf",
            "value": "95"
        }
    ],
    [
        {
            "name": "vaRType",
            "value": "INCRE"
        },
        {
            "name": "per",
            "value": "100"
        },
        {
            "name": "hor",
            "value": "95"
        },
        {
            "name": "conf",
            "value": "95"
        }
    ]
]

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