這是一個初學者的問題, 我怎麼會格式字符串以下JSON數組的std :: string格式JSON代碼到的std :: string
[
{
"x" : 12.1,
"y" : 12.1,
"z" : 12.1
},
{
"x" : 12.1,
"y" : 12.1,
"z" : 12.1
},
{
"x" : 12.1,
"y" : 12.1,
"z" : 12.1
},
{
"x" : 12.1,
"y" : 12.1,
"z" : 12.1
}
]
這裏是JSON字符串
const std::string json =
"[\n"
" {\n"
" \"x\" : 0,\n"
" \"y\" : 0,\n"
" \"z\" : 0\n"
" },\n"
" {\n"
" \"x\" : 640,\n"
" \"y\" : 0,\n"
" \"z\" : 0\n"
" },\n"
" {\n"
" \"x\" : 640,\n"
" \"y\" : 0,\n"
" \"z\" : 480\n"
" },\n"
" {\n"
" \"x\" : 0,\n"
" \"y\" : 0,\n"
" \"z\" : 480\n"
" }\n"
"]\n";
Json::Value coordinates;
Json::Reader reader;
reader.parse(json, coordinates);
所以我試圖解析上面的json數組,以獲得座標列表,但它不能被正確解析。
的Json * *是一個字符串。這不是代碼。 '「[{」x:12.1},{「x」:12.1「}]」'是一個Json字符串。你什麼意思?您是否試圖創建一個 –
我的問題如何將json寫入std :: string – andre
就像任何其他字符串一樣。 Json是一個字符串,其內容具有特定的格式。而已。 –