git clone https://github.com/Tencent/rapidjson.git
待续
http://sourceforge.net/projects/jsoncpp/files/
http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download
tar -zvxf scons-2.1.0.tar.gz
我的解压到了/opt/JSON/scons-2.1.0目录下了
sudo python setup.py install
tar -zvxf jsoncpp-src-0.5.0.tar.gz
我的解压到了/opt/JSON/jsoncpp-src-0.5.0下
sudo scons platform=linux-gcc
拷贝动态库
将jsoncpp-src-0.5.0/libs/linux-gcc-4.9.1/目录下的libjson_linux-gcc-4.9.1_libmt.a 拷贝到/usr/local/lib/下,并为了方便使用,将其重命名为libjson.a
实例
#include
#include
using namespace std;
int main()
{
string test="{\"id\":1,\"name\":\"kurama\"}";
Json::Reader reader;
Json::Value value;
if(reader.parse(test,value))
{
if(!value["id"].isNull())
{
cout<
g++ test.cpp -I include -L libs/linux-gcc-9 -ljson_linux-gcc-9_libmt
https://sourceforge.net/projects/cjson/
➜ cJSON gcc cJSON.c test.c -o test_json -lm
➜ cJSON ls
cJSON.c cJSON.h LICENSE README test.c test_json tests
https://blog.csdn.net/nanfeibuyi/article/details/86605234
test.json
{
"menu": {
"id": "file",
"value": "File:",
"popup": {
"menuitem": {
"value": "New",
"onclick": "CreateNewDoc()"
}
}
}
}
json.sh
#! /bin/bash
JQ_EXEC=`which jq`
FILE_PATH=test.json
id = $(cat $FILE_PATH | jq '.errmsg.requirement1.code' | awk '{print int($2)}')
echo $id
id = $(cat $FILE_PATH | jq '.errmsg.requirement1.code' | awk -F '"' '{print $2}')
echo $id
id=$(cat $FILE_PATH | ${JQ_EXEC} .menu.id | sed 's/\"//g')
echo $id
输出
JQ_EXEC:/usr/bin/jq
file
示例,基于以下输入字符串 – 输出是stdout:
jsonStr='{ "key1": "value1","key3": "value3" }'
删除“key3”:
jq 'del(.key3)' <<<"$jsonStr"
添加属性“key4”,值为“value4”:
jq '. + { "key4": "value4" }' <<<"$jsonStr"
将现有属性“key1”的值更改为“new-value1”:
jq '.key1 = "new-value1"' <<<"$jsonStr"
如果要在现场更新JSON文件(概念上讲),请使用删除“key3”的示例:
# Create test file.
echo '{ "key1": "value1","key3": "value3" }' > test.json
# Remove "key3" and write results back to test.json (recreate it with result).
jq -c 'del(.key3)' test.json > tmp.$$.json && mv tmp.$$.json test.json
您无法直接替换输入文件,因此将结果写入临时文件,成功替换输入文件.
有一个example.txt文件,文件内容如下:
{“err_code”:200,”err_msg”:”this is no error”,“status”:1,“dev_name”:“mylinux”,“dev_id”:123}
如果我们想要获取dev_id字段的值,可以在命令行下使用如下一行命令:
cat example.txt | sed ‘s/,/\n/g’ | grep “dev_id” | sed ‘s/:/\n/g’|sed ‘1d’ | sed ‘s/}//g’
https://www.cnblogs.com/gouge/p/7090469.html
https://stedolan.github.io/jq/download
http://blog.chinaunix.net/uid-24774106-id-3830242.html
https://blog.csdn.net/qq_26502245/article/details/100191694
https://www.cnblogs.com/yjt1993/p/10028089.html
https://www.cnblogs.com/yjb333/p/10370521.html