简体   繁体   中英

JSON string not deserializing

I have a problem with deserializing this JSON data due to duplicate property name value and value_raw .

I have attempted to use a List based object to deserialize the values but this only results in the last value being stored in the object. Apart from this, the object resolves correctly.

JSON string:

{
    "prtg-version":"9.2.0.2236",
    "treesize":576,
    "values":
        [{
            "datetime":"29/09/2012 09:45:00 - 09:50:00",
            "datetime_raw":41181.3680555556,
            "value":"49 %",
            "value_raw":48.5000,
            "value":"0 %",
            "value_raw":0.0000,
            "coverage":"100 %",
            "coverage_raw":"0000010000"
        }]
}  

Please note - the JSON string is what i get back from PRTG, so unfortunately i have to work with it in that format :(

You can not deserialize that as the string you provided is NOT a valid JSON. By RFC, all attribute names inside one objects should be unique. The only reasonable way to tackle that - rewrite the part of code where this string comes from.

can you first serialise the

            "datetime":"29/09/2012 09:45:00 - 09:50:00",
            "datetime_raw":41181.3680555556,
            "value":"49 %",
            "value_raw":48.5000,
            "value":"0 %",
            "value_raw":0.0000,
            "coverage":"100 %",
            "coverage_raw":"0000010000"

into a List of string and then do further process after?

"datetime"    :"29/09/2012 09:45:00 - 09:50:00",
"datetime_raw":41181.3680555556,
"value"       :["49 %","0 %"]
"value_raw"   :[48.5000,0.0000]            
"coverage"    :"100 %",
"coverage_raw":"0000010000"

change the value and value_raw as shown above

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