文字列になってしまいどうにもなりません
なに言ってんだかわかんない。picojsonはstreamからjson受け取ってparseできるっしょ。
// 読み込むと実行できない
実行できないってナニ? コンパイルエラー? リンクエラー? 実行時エラー?
'なにをしたらどうなった'を明記せよ。
example.json
json
1{
2 "Image": {
3 "Width": 800,
4 "Height": 600,
5 "Title": "View from 15th Floor",
6 "Thumbnail" : {
7 "Url": "http://www.example.com/image/481989943",
8 "Height": 125,
9 "Width": "100"
10 },
11 "IDs": [116, 943, 234, 38793]
12 }
13}
sample.cpp
C++
1#include <picojson.h>
2
3#include <iostream>
4#include <cassert>
5#include <string>
6
7//using namespace std;
8using namespace picojson;
9
10int main() {
11 value root;
12 std::cin >> root;
13 assert( get_last_error().empty() );
14
15 object image = root.get<object>()["Image"].get<object>();
16 std::cout << "Width=" << image["Width"].get<double>() << std::endl;
17 std::cout << "Height=" << image["Height"].get<double>() << std::endl;
18 std::cout << "Title=" << image["Title"].get<std::string>() << std::endl;
19 array ids = image["IDs"].get<array>();
20
21 for ( value item : ids ) {
22 std::cout << item.get<double>() << std::endl;
23 }
24}
compile/run
E:\ProgramData\work\picojson-master>cl -EHsc -I. sample.cpp
Microsoft(R) C/C++ Optimizing Compiler Version 19.10.25017 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
sample.cpp
Microsoft (R) Incremental Linker Version 14.10.25017.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:sample.exe
sample.obj
E:\ProgramData\work\picojson-master>sample < example.json
Width=800
Height=600
Title=View from 15th Floor
116
943
234
38793
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/25 06:41
2017/07/25 06:43
2017/07/25 06:59
2017/07/25 09:25