Hi everyone,
There are a number of posts here about parsing JSON files, but none that use the DotNet Newtonsoft JSON library.
Has anyone used the DotNet library Newtonsoft.Json.Linq.JObject to read specific key/value pairs from a JSON string?
I've loaded values into a Json Object:
{
"item": {
"ID": "72795",
"Latitude": "34.045358",
"Longitude": "-118.443574",
"ZipCode": "90025",
"CityAliasAbbr": null,
"AreaCode": "310/424/818",
"City": "LOS ANGELES",
"CountyName": "LOS ANGELES",
"CityAliases": {
"Item": [
{
"ID": "72795",
"Primary": "P",
"CityType": "P",
"CityAliasName": "LOS ANGELES",
"MixedCaseAlias": "Los Angeles"
},
{
"ID": "72796",
"Primary": " ",
"CityType": "N",
"CityAliasName": "W LOS ANGELES",
"MixedCaseAlias": "W Los Angeles",
},
{
"ID": "72797",
"Primary": " ",
"CityType": "N",
"CityAliasName": "WEST LOS ANGELES",
"MixedCaseAlias": "West Los Angeles",
},
]
}
}
}
I can retrieve the "item" key using:
IF JObject.TryGetValue('item',JToken) THEN BEGIN
JProperty := JObject.Property(propertyName);
value := JProperty.Value;
END;
The value returned is the entire Json string as above.
But I want to retrieve ONLY the "Latitude" and "Longitude" key-value pairs.
I've tried:
IF JObject.TryGetValue('[item][Longitude]',JToken) THEN BEGIN...
IF JObject.TryGetValue('item,Longitude',JToken) THEN BEGIN...
But both return <blank>.
There are numerous examples out on the web for C# or Javascript that say this can be done, i.e. you don't have to parse the entire string and check each key-value pair for the one you want. But the syntax doesn't translate to C/AL. for example:
JObject rss = JObject.Parse(json);
string rssTitle = (string)rss["item"]["Longitude"];
Does anyone know how to read a specific key-value pair in C/AL that is "nested" inside another key?