JSON string not deserializing

367 Views Asked by At

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 :(

3

There are 3 best solutions below

2
On BEST ANSWER

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.

0
On

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?

0
On
"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