{ "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", }, ] } } }
IF JObject.TryGetValue('item',JToken) THEN BEGIN JProperty := JObject.Property(propertyName); value := JProperty.Value; END;
IF JObject.TryGetValue('[item][Longitude]',JToken) THEN BEGIN... IF JObject.TryGetValue('item,Longitude',JToken) THEN BEGIN...
JObject rss = JObject.Parse(json); string rssTitle = (string)rss["item"]["Longitude"];
Latitude := JObject.SelectToken('item.Latitude');
Valor := JObject.SelectToken('item.CityAliases.Item[0].ID');
Answers
Have you try to use SelectToken.
Latitude must to be a variant variable and deal with it.
Regards.
OK, the above line worked great for the keys in the "first level" like "Latitude".
Now I want to loop through the "CityAliases"
I can move the "City Aliases" key and all its sub-values into a separate JsonObject, but when I try to query for values within each "Item" in a FOREACH loop, I get NULL, e.g.
Any ideas?
Ue this to get the ID of the first item a so on.
Regards
While using the
JObject1 := JObject1.SelectToken('packDoneDetails.packingBoxDetails');
I am getting the below error. Can you please help me out.
A DotNet variable has not been instantiated. Attempting to call Newtonsoft.Json.Linq.JObject.SelectToken in CodeUnit MAVEN Integration: ParseJSONResponse
You need to change this
to this
packDoneDetails, in your JSON data, is an array.
Regards
See the first message in this thread to see the full JSON being retrieved. It has a "nested" array (set of key-value pairs) for "CityAliases". I want to loop through those Aliases.
We're working in NAV2016, so I took the Json Management codeunit from BC and downgraded it to C/AL, but the functions are the same.
The "JsonString" parameter passed is the full JSON result as shown in the first message:
There may be a more "efficient" way of moving the JSON CityAliases Subset to an array for looping through, but I was using the functions in the JSON Management codeunit.
In a JSON Array, the first element is [0], so my loop takes my counter which starts at 1 and subtracts 1 to get the array member.
{
"item": {
"ID": "72795",
"ZipCode": "90025",
"City": "LOS ANGELES",
"CityAliases": {
"Item": [
{
"ID": "72795",
"Primary": "P",
"CityType": "P",
},
{
"ID": "72796",
"Primary": "",
"CityType": "N",
},
{
"ID": "72797",
"Primary": "",
"CityType": "N",
},
]
}
}
}
This is my JSON response
"27675":{
"entity_id":"27675",
"status":"complete",
},
"27676":{
"entity_id":"27676",
"status":"complete",
},
"27677":{
"entity_id":"27677",
"status":"complete",
can we read "27675", "27676"..... these numbers?