Ali Raza
Ali Raza

Reputation: 7

Json parsing using rapidJson in c++ giving Error

The given string Format is given Below:

"{"success":"yes","error":"","message":"","arguments":"[{\"assetId\":\"7384\",\"assetSerialNo\":\"Base Map\",\"assetDescription\":\"\",\"assetVersion\":\"\",\"assetIsMovable\":\"f\",\"assetType\":\"Layer\",\"assetModel\":\"Tile\",\"parentId\":\"7362\",\"assetIsTrackable\":\"f\",\"assetInheritsRegion\":\"f\",\"assetRegion\":\"\",\"typeId\":\"15\"}]"}"

Object within an array and that array is within an Object. But when I parse this string :

document.h is included

Document obj; obj.Parse<0>(json);

It give an error :

document.h:1718:22: note: template rapidjson::GenericDocument& rapidjson::GenericDocument::Parse(const Ch*) [with unsigned int parseFlags = parseFlags, SourceEncoding = SourceEncoding, Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, StackAllocator = rapidjson::CrtAllocator, rapidjson::GenericDocument = rapidjson::GenericDocument >, rapidjson::GenericDocument::Ch = char] document.h:1729:22: note: template rapidjson::GenericDocument& rapidjson::GenericDocument::Parse(const Ch*) [with unsigned int parseFlags = parseFlags, Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, StackAllocator = rapidjson::CrtAllocator, rapidjson::GenericDocument = rapidjson::GenericDocument >, rapidjson::GenericDocument::Ch = char]

How I json Decode that format and retrieve assetId .The main object does not have \"\" around string as As this format is returned from an api ?

Upvotes: 0

Views: 1393

Answers (1)

Mickael T
Mickael T

Reputation: 975

According https://jsonlint.com/ a valid JSON would be more like this:

"{"success":"yes","error":"","message":"","arguments":" [{"assetId":"7384","assetSerialNo":"Base Map","assetDescription":"","assetVersion":"","assetIsMovable":"f","assetType":"Layer","assetModel":"Tile","parentId":"7362","assetIsTrackable":"f","assetInheritsRegion":"f","assetRegion":"","typeId":"15"}]}"

Upvotes: 0

Related Questions