Linux下jsoncpp的安装使用
https://blog.csdn.net/zhaojunwuiris/article/details/85773294https://www.cnblogs.com/fengbohello/p/4059435.htmlpythonrm /usr/bin/python#删除之前的python2的软连接ln -s /usr/local/python3/bin/python3.7 /usr/bin/p
·
https://blog.csdn.net/zhaojunwuiris/article/details/85773294
https://www.cnblogs.com/fengbohello/p/4059435.html
python
rm /usr/bin/python
#删除之前的python2的软连接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
#新建一个软连接到python修改默认版本python和yum
error while loading shared libraries: libjson.so: cannot open shared object file: No such file or directory
[root@instance-sutadosy moleserver]# ./testjson
./testjson: error while loading shared libraries: libjson.so: cannot open shared object file: No such file or directory
[root@instance-sutadosy moleserver]# ld
ld ldattach ld.bfd ldconfig ldd ld.gold
[root@instance-sutadosy moleserver]# ldconfig
[root@instance-sutadosy moleserver]# ./testjson
json
jsoncpp
{
"array" : [
{
"cpp" : "jsoncpp",
"java" : "jsoninjava",
"php" : "support"
}
],
"name" : "json"
}
/*
g++ testjson.cpp -o testjson -ljson
*/
#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
void readJson();
void writeJson();
int main(int argc, char** argv) {
readJson();
writeJson();
return 0;
}
void readJson() {
using namespace std;
std::string strValue = "{\"name\":\"json\",\"array\":[{\"cpp\":\"jsoncpp\"},{\"java\":\"jsoninjava\"},{\"php\":\"support\"}]}";
Json::Reader reader;
Json::Value value;
if (reader.parse(strValue, value))
{
std::string out = value["name"].asString();
std::cout << out << std::endl;
const Json::Value arrayObj = value["array"];
for (unsigned int i = 0; i < arrayObj.size(); i++)
{
if (!arrayObj[i].isMember("cpp"))
continue;
out = arrayObj[i]["cpp"].asString();
std::cout << out;
if (i != (arrayObj.size() - 1))
std::cout << std::endl;
}
}
}
void writeJson() {
using namespace std;
Json::Value root;
Json::Value arrayObj;
Json::Value item;
item["cpp"] = "jsoncpp";
item["java"] = "jsoninjava";
item["php"] = "support";
arrayObj.append(item);
root["name"] = "json";
root["array"] = arrayObj;
root.toStyledString();
std::string out = root.toStyledString();
std::cout << out << std::endl;
}
更多推荐



所有评论(0)