Home > Back-end >  Jsoncpp parsing json, meet individual characters returns false parsing
Jsoncpp parsing json, meet individual characters returns false parsing

Time:09-29

With jasoncpp parsing json meet individual words may not be able to parse, parsedOk returns false,
 
AnsiString sJson="XXXXXX";
Json: : Reader Reader;
Json: : Value json_Value;
Bool parsedOk=reader. Parse (sJson c_str (), json_Value);
If (! ParsedOk)
{
}


Can't parse text list:
乗 Oregon Deng Wan Ke Bo 圽 time-lag prize 媆 峔 嶾 廫 慭 怽 揬 昞, 梊 榎 橽 歕 沑 漒 瀄 焅 ? 猏 protecting 琝 甛 Jin 痋 盶 癨 瞈 砛 Qi 穃 竆 筡
篭 糪 Gua organ Cui 繺 羂 耚 肻 腬 臶 臷 芢 蒤 薥 Zhong 蝄 mite the mite 裓
覾 譢 豛 赲 踈 躙 輁 郳 light 鈂 bowl e ? ? ? 鏫 Han Han 隲 e ? ? ˉ Si e ? ?鯸 鮘 鳿 e ? ? - Shi

CodePudding user response:

AnsiString into UnicodeString

Json does matter, or is likely to use string decoder TEncoding

CodePudding user response:

JasonCpp when processing utf-8 encoded string is no problem, because the ANSI code is too complex, too many shortcomings, many functions with error, JasonCpp cannot handle AnsiString is understandable,

Substitute UTF8String AnsiString, shall be with the UNICODE string was no problem, avoid the ANSI don't appear anywhere, string constants are written in the L "" UNICODE strings,

UTF8String sJson=L "XXXXXX";

UTF8String and can be directly assigned to each other between UnicodeString
UTF8String and STD: : string can be directly assigned to each other between
STD: : string and need to use UTF8String transit between UnicodeString
 
Would would be * *
↘ ↙ ↗
STD: : string please - UTF8String please - UnicodeString
↗ ↖
L "string" L "string"


According to the rules, here's the STD: : string and UTF8String if and char * transform each other, is utf-8, ANSI

CodePudding user response:

 
Would would be * *
↘ ↙ ↗
STD: : string please - UTF8String please - UnicodeString
↗ ↖
L "string" L "string"

CodePudding user response:

According to the rules, here's the STD: : string and UTF8String is utf-8, ANSI, if the STD: : string and the conversion between char *, convert between UTF8String and char *, is utf-8, program once appear, ANSI code inside, will go wrong,

CodePudding user response:

reference 4 floor ybchen response:
according to the rules, here's the STD: : string and UTF8String is utf-8, ANSI, if the STD: : string and the conversion between char *, convert between UTF8String and char *, is utf-8, program once appear, ANSI code inside, will go wrong,

Thanks for your great advice, I have seen the explanation I also understand that, but there is a problem, this jsoncpp parameter format fixed dead, I changed the compiler is not in the past, can only change jsoncpp source, but my ability is limited may can't do that, I just want to ask, is this is a bug jsoncpp, how can I be a little bit more simple to solve this problem, c + + builder inside seem to parse the json can only use this jsoncpp,

CodePudding user response:

In c + + Builder can parse the JSON library has a lot of, but can code is less, which is more convenient JSONCPP, but it is certainly not the fastest, CB itself also took a JSON encoding decoding library,

CodePudding user response:

Jsoncpp can refer to the program, support UNICODE, language is supported by countries around the world, is not only Chinese characters,
http://www.cppfans.com/sdk/json/jsoncpp.asp

CodePudding user response:

The final passing are UnicodeString

CodePudding user response:

I didn't run into problems of the building Lord ah, test is no problem with the building code I?

CodePudding user response:

Well, there are problems, just wrong

CodePudding user response:

String ss="乗 Oregon Deng Wan Ke Bo 圽 time-lag prize 媆 峔 嶾 廫 慭 怽 揬 昞, 梊 榎 橽 歕 沑 漒 瀄 焅 ? 猏 protecting 琝 甛 Jin 痋 盶 癨 瞈 砛 Qi 穃 竆 筡";
Root [" firstName "]=AnsiString (ss). The c_str ();
Json: : StyledWriter styled_writer;
Int l=styled_writer. Write (root). The length ();

Char * s1=new char [1024].
Memset (s1, 0, 1024);
Strncpy (s1, styled_writer. Write (root). The c_str (), l);

//parsing
Json: : Reader Reader;
Json: : Value json_object;
if (! Reader. Parse (s1, json_object))
ShowMessage (" error ");
The else
ShowMessage (json_object [r]. "firstName" asString (). The c_str ());


The code above tests pass, bcb2010

CodePudding user response:

11 references LinuxCard response:
String ss="乗 Oregon Deng Wan Ke Bo 圽 time-lag prize 媆 峔 嶾 廫 慭 怽 揬 昞, 梊 榎 橽 歕 沑 漒 瀄 焅 ? 猏 protecting 琝 甛 Jin 痋 盶 癨 瞈 砛 Qi 穃 竆 筡";
Root [" firstName "]=AnsiString (ss). The c_str ();
Json: : StyledWriter styled_writer;
Int l=styled_writer. Write (root). The length ();

Char * s1=new char [1024].
Memset (s1, 0, 1024);
Strncpy (s1, styled_writer. Write (root). The c_str (), l);

//parsing
Json: : Reader Reader;
Json: : Value json_object;
if (! Reader. Parse (s1, json_object))
ShowMessage (" error ");
The else
ShowMessage (json_object [r]. "firstName" asString (). The c_str ());


The code above tests pass, bcb2010


Specific how to do?
  • Related