直接看代码:
#include <iostream>
#include <stdio.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<sstream>
// 请自己下载开源的rapidjson
#include "rapidjson/prettywriter.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/memorystream.h"
using namespace std;
using rapidjson::Document;
using rapidjson::StringBuffer;
using rapidjson::Writer;
using namespace rapidjson;
string getStringFromJson(const string &jsStr, const string &strKey)
{
Document document;
if (document.Parse(jsStr.c_str()).HasParseError() || !document.HasMember(strKey.c_str()))
{
return "";
}
const rapidjson::Value &jv = document[strKey.c_str()];
return jv.GetString();
}
int main(int argc, char *argv[])