I have been searching quite a while now for how to read a nested JSON with C++ Builder XE2 TJSONObject
.
There are a few examples in Delphi but they use the TJSONValue
object, but in the C++ version this class has a pure virtual function and can not be created.
Some example JSON:
{
"totalHits": 4170,
"totalCount": 4170,
"startIndex": 0,
"adverts": [
{
"Id": "14380005",
"companyInfo": {
"companyName": "Clarion Hotel Sign",
"orgNumber": "5564660107",
"companyText": "hotell"
},
"address": {
"streetName": "Street race 2",
"postCode": "101 26",
"postArea": "MY AREA",
"postBox": "Box 310"
},
"homepage": "www.mypage.net"
}
]
}
The whole JSON is stored in the JSON object, trust me, it's in there :)
TJSONObject *JSON = new TJSONObject;
I have no problem to get the value for totalHits and totalCount, but how do I get the "companyName"
value?!?
Thanks
I post this belated answer for someone else who meets the same problems in the future....
TJSONArray* jArray = (TJSONArray* )JSON->Get("adverts")->JsonValue;
TJSONObject* jCompanyInfo = (TJSONObject*)((TJSONObject*)jArray->Get(0))
->Get("companyInfo")->JsonValue);
String companyName = jCompanyInfo->Get("companyName")->JsonValue->Value());