Json在c ++中使用rapidJson进行解析,给出了Error

时间:2014-10-29 10:12:44

标签: c++ json rapidjson

给定的字符串格式如下:

"{"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中。但是当我解析这个字符串时:

包含document.h

  

文件对象;   obj.Parse&℃,GT;(JSON);

它出错了:

  

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

我如何解码该格式并检索assetId。主要对象没有\" \"围绕字符串as这种格式是从api?

返回的

1 个答案:

答案 0 :(得分:0)

根据 https://jsonlint.com/,一个有效的 JSON 会更像这样:

"{"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"}]}"