Question

I am trying to parse a json string returned from the xively feed from an Air Quality Egg. One of the properties says whether the xively feed is public or private. The property is called private and takes the string value "true" or "false". To get data from the feed I am calling xively's Historical Data REST API which successfully returns me valid JSON. I am then using JSON.NET to parse the JSON in C#. My parsing starts thus:

dynamic historicalDatapoints  = JValue.Parse(jsonString) as JObject;
if (historicalDatapoints != null)
{
    var id = historicalDatapoints.id;
    var title = historicalDatapoints.title.ToString();
    var privacy = bool.Parse(historicalDatapoints.private.ToString())
    // More parsing
}

I have a problem with that last line of code. C# will not let me refer to the property called "private". Here's the corresponding (redacted) JSON:

{
    "id": 000000843,
    "title": "Blah Road Egg 02",
    "private": "false",
    //...
}

Using JSON.NET how should I parse out the property private?

Was it helpful?

Solution

Try historicalDatapoints.@private to access that value. If that doesn't work then you could also try historicalDatapoints["private"]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top