Я обнаружил, что использование библиотеки JsonCpp, проанализированной строки json A, не может быть разрешено, странно то, что анализ строки B разрешается успешно, когда я беру содержимое строки при сбое программы, вот почему? Как избежать сбоя?(строка A:"http://192.168.1.1";строка B:"192.168 .1.1";)
#include"include/json/json.h"
#include <iostream>
int main(int argc, char** argv)
{
//compile:g++ -o test json_value.cpp json_writer.cpp json_reader.cpp json_test.cpp -I./include
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( "192.168.1.1", root );//http://192.168.1.1
if ( !parsingSuccessful )
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n"
<< reader.getFormattedErrorMessages();
return 0;
}
else
{
std::cout << "Successfully parse configuration" << endl;
}
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
// such member.
std::string encoding = root.get("encoding", "UTF-8" ).asString();
// And you can write to a stream, using the StyledWriter automatically.
std::cout << "encoding:" <<encoding << endl;
return 0;
}