joncmu / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Document as a class member? #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. See attach file, its hard to explain

What is the expected output? What do you see instead?
If i understand Document correctly, 
- the expected output for TEST1 under Level 1 score should be 100. 
- the expected output for TEST2 under Level 1 score should be 1337

What version of the product are you using? On what operating system?
v0.11, Windows 7 64bit

Please provide any additional information below.
Please see attach file. Includes: 
- testjson.h
- testjson.cpp

Original issue reported on code.google.com by Jeffrey...@gmail.com on 12 Apr 2013 at 11:31

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
doc.AddMember(lvl.c_str(), score, doc.GetAllocator());

lvl.c_str() is a temp string, it needs to be duplicated, otherwise when the 
function returns the pointer become invalid.

For this situation, you should call
rapidjson::Value name(lvl.c_str(), doc.GetAllocator()); // copy the string
rapidjson::Value value(score);
doc.AddMember(name, value, doc.GetAllocator());

I think it is kinda confusing at first. I will consider making the API more 
safe.

Original comment by milo...@gmail.com on 1 Jul 2014 at 1:32

GoogleCodeExporter commented 9 years ago
Further discussion will be in
https://github.com/miloyip/rapidjson/issues/38

Original comment by milo...@gmail.com on 1 Jul 2014 at 2:07