Shivani Sarin
Shivani Sarin

Reputation: 1

How to return json string of arrays using rapidjson

I have a json file which looks like this

{
    "ActivityId":"CB8FA1DA-DCB4-40B3-9D12-2786BD89B4D4",
    "AdditionalParams":{
        
    }, 

    "Extensions":[
        {
            "Id":"1234",
            "IsEnabled":false,
            "Name":"Name1"
        },
        {
            "Id":"4567",
            "IsEnabled":false,
            "Name":"Name2"
        },
        {
            "Id":"8910",
            "IsEnabled":true,
            "Name":"Name3"
        }
    ]
}

I see a lot of code online which tries to get the IsEnabled,Name fields(as an example). However, I am trying to use rapidjson to print out the array of extensions as is.

Here is the code that I have tried

 Document document;
    document.Parse(json);
   if (document.HasMember(L"Extensions")) {     
        eventPayload = document[L"Extensions"].GetString();
    }

Upvotes: 0

Views: 341

Answers (1)

PrabanjanRaja
PrabanjanRaja

Reputation: 55

document[L"Extensions"] is not a string, it's an array, so you will have to first getArray, then iterate through it with a JSONIterator and then get the value of IsEnabled.

Also, you don't have to use L"", since they are normal strings and not wide strings.

Upvotes: 1

Related Questions