ctelroy / rapidjson Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/rapidjson
License: MIT License
Automatically exported from code.google.com/p/rapidjson
License: MIT License
Rapidjson v0.1 Copyright (c) 2011 Milo Yip ([email protected]) http://code.google.com/p/rapidjson/ 19 Nov 2011 1. Introduction Rapidjson is a JSON parser and generator for C++. It was inspired by rapidxml http://rapidxml.sourceforge.net/ Rapidjson is small but complete. It supports both SAX and DOM style API. The SAX parser is only a half thousand lines of code. Rapidjson is fast. Its performance can be comparable to strlen(). It also optionally supports SSE2/SSE4.1 for acceleration. Rapidjson is self-contained. It does not depend on external libraries such as BOOST. It even does not depend on STL. Rapidjson is memory friendly. Each JSON value costs exactly 16/20 bytes for 32/64-bit machines (excluding text string). By default it uses a fast memory allocator, and the parser allocates memory compactly during parsing. For the full features please refer to the user guide. JSON(JavaScript Object Notation) is a light-weight data exchange format. More information about JSON can be obtained at http://json.org/ http://www.ietf.org/rfc/rfc4627.txt 2. Installation Rapidjson is a header-only C++ library. Just copy the rapidjson/include/rapidjson folder to system or project's include path. To build the tests and examples, 1. obtain premake4 http://industriousone.com/premake/download 2. Copy premake4 executable to rapidjson/build 3. Run rapidjson/build/premake.bat on Windows, rapidjson/build/premake on Linux or other platforms 4. On Windows, build the solution at rapidjson/build/vs2008/ or /vs2010/ 5. On other platforms, run GNU make at rapidjson/build/gmake/ (e.g., make -f test.make config=release32, make -f example.make config=debug32) 6. On success, the executable are generated at rapidjson/bin
What steps will reproduce the problem?
Having a problem regarding Value functions in document.h. Functions
HasMember(), GetString() work when the whole JSON object is received. Is there
a way to overcome this issue? For example, when looking for values on the fly
is required, when JSON text sent in chunks. As an example, the following
produces an error, as there is no an ending curly brace:
char buf[]=("{ \"objectType\" : \"world\" ");
Document d;
d.Parse<0>(buf);
Value *src = &d;
if((*src).HasMember("objectType")==true)
{
puts((*src)["objectType"].GetString());
}
Would be nice, if smth can be done with it.
What is the expected output? What do you see instead?
Assertion failed: Isobject()...document.h, line 614
What version of the product are you using? On what operating system?
Rapidjson v0.1, Windows 7,64 bit
Original issue reported on code.google.com by [email protected]
on 22 May 2012 at 9:19
Hi folks:
I am trying to use rapidjson to get two value pairs unknown from a server. I
mean sort like { "x":"y" } both x and y unknown (several of this pairs) and I
couldn't find a demo to do that in rapidjson. I need to get/print both values.
I think it would be great to have one around in the examples. All I could see
are, getting predetermined values and some sort of iterators that are not easy
to get. I mean to understand.
Original issue reported on code.google.com by [email protected]
on 13 Jan 2012 at 4:07
What steps will reproduce the problem?
1.Create new object
2.Add some values to it
3.Remove last added value
Source code bellow:
int main(int argc, char* argv[])
{
rapidjson::Document doc;
rapidjson::StringBuffer strBuff(0, 1024);
rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
rapidjson::Value objVal(rapidjson::kObjectType);
objVal.AddMember("var1", 123, allocator);
objVal.AddMember("var2", "444", allocator);
objVal.AddMember("var3", 555, allocator);
objVal.RemoveMember("var3");
strBuff.Clear();
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(strBuff);
objVal.Accept(writer);
printf("Created string: %s\n", strBuff.GetString());
return 0;
}
What is the expected output? What do you see instead?
Expecting ouput of created object as string.
Assert happens, when removing object's member
What version of the product are you using? On what operating system?
Using code from repository, r61
Windows7 x64
Original issue reported on code.google.com by [email protected]
on 29 Feb 2012 at 9:37
I writen some codes to test read/write chinese.
char json_test_utf8_chinese[] = {(char)228, (char)184, (char)173};
char* chinese_json = "{\"chinese\": \"\\u4e2d\"}";
rapidjson::Document document;
ASSERT_FALSE(document.Parse<0>(chinese_json).HasParseError());
EXPECT_TRUE(document.HasMember("chinese"));
LOG(INFO) << document["chinese"].GetString() << std::endl;
EXPECT_STREQ(json_test_utf8_chinese, document["chinese"].GetString());
rapidjson::StringBuffer s(0, 65535);
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
document.Accept(writer);
LOG(INFO) << "json size: " << s.GetSize() << " bytes";
LOG(INFO) << s.GetString();
google::FlushLogFiles(INFO);
Test passed, but the log shown the chinese characters ware not encode as
"\uXXXX" format.
Log as below:
I1011 17:30:58.483409 2880 main.cpp:2076] 中
I1011 17:30:58.484410 2880 main.cpp:2082] json size: 11 bytes
I1011 17:30:58.484410 2880 main.cpp:2083] {"1":"中"}
Original issue reported on code.google.com by [email protected]
on 11 Oct 2012 at 9:39
Hi, thanks for a great package. I have a suggested fix below. Please have a
look.
What steps will reproduce the problem?
1. Compile with clang 3.1
What version of the product are you using? On what operating system?
rapidjason 0.1 (the problem is the same in svn trunk)
Linux, ubuntu 10.12
Please provide any additional information below.
In the file include/rapidjson/document.h
The ParseStream method (around line 704) seems to use ill-defined C++ which
slips through gcc. In my understanding is that clang is right to reject this.
The issue is that dependent names need template qualification inside templates.
To me clang is right to demand that the meaning of these names be more clearly
specified. I suggest to change:
reader.Parse<parseFlags> into
reader. template Parse<parseFlags>
and
this->RawAssign into
RawAssign
This builds correctly both with gcc (4.4) and clang (3.1)
Here's the complete method with those fixes:
template <unsigned parseFlags, typename Stream>
GenericDocument& ParseStream(Stream& stream) {
ValueType::SetNull(); // Remove existing root if exist
GenericReader<Encoding> reader;
if (reader. template Parse<parseFlags>(stream, *this)) {
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
this->RawAssign(*stack_.template Pop<ValueType>(1));
parseError_ = 0;
errorOffset_ = 0;
}
else {
parseError_ = reader.GetParseError();
errorOffset_ = reader.GetErrorOffset();
ClearStack();
}
return *this;
}
Full compilation error below
----------------------------
dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:708:7: error: reference to non-static member function must be called
if (reader.Parse<parseFlags>(stream, *this)) {
^~~~~~~~~~~~
dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:741:10: note: in instantiation of function template specialization
'rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::ParseStream<0,
rapidjson::GenericStringStream<rapidjson::UTF8<char> > >' requested here
return ParseStream<parseFlags>(s);
^
x.cpp:78:6: note: in instantiation of function template specialization
'rapidjson::GenericDocument<rapidjson::UTF8<char>,
rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::Parse<0>' requested here
doc.Parse<0>(cfg);
^
In file included from y.h:4:
dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:708:19: error: invalid operands to binary expression
('<bound member function type>' and 'unsigned int')
if (reader.Parse<parseFlags>(stream, *this)) {
~~~~~~~~~~~~^~~~~~~~~~~
2 errors generated.
Original issue reported on code.google.com by [email protected]
on 18 Oct 2012 at 1:35
What steps will reproduce the problem?
1. Build rapidjson toturial.cpp using any clang tool chain. I used Apple Xcode
4.2.
What is the expected output? What do you see instead?
The file compiles and builds successfully.
What version of the product are you using? On what operating system?
0.1 with Apple XCode 4.2 on OS X 10.6. But this is independent of OS.
Please provide any additional information below.
clang errors with the following:
/Users/stephenchu/Dropbox/Mac
Client/Client/../rapidjson/include/rapidjson/document.h:706:4: error: use of
undeclared identifier 'RawAssign' [3]
RawAssign(*stack_.template Pop<ValueType>(1));
^
This is a know issue with clang. The issue and solution can be found here:
http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html
Adding qualifier this to the call fixes the problem:
this->RawAssign(*stack_.template Pop<ValueType>(1));
Original issue reported on code.google.com by [email protected]
on 10 Feb 2012 at 6:47
GenericDocument::ParseStream() does not pass custom memory allocator to
GenericReader template in document.h:703. Proposed patch
Index: document.h
===================================================================
--- document.h
+++ document.h
@@ -700,7 +700,7 @@
template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
GenericDocument& ParseStream(InputStream& is) {
ValueType::SetNull(); // Remove existing root if exist
- GenericReader<SourceEncoding, Encoding> reader;
+ GenericReader<SourceEncoding, Encoding, Allocator> reader;
if (reader.Parse<parseFlags>(is, *this)) {
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
this->RawAssign(*stack_.template Pop<ValueType>(1)); // Add this-> to prevent issue 13.
Original issue reported on code.google.com by [email protected]
on 12 Jun 2012 at 10:06
Hello,
I am trying to serialize a JSON document to a string and I am not able to do
it. I have been reading the examples but I don´t find nothing similar. In all
the examples the serializing text is redirected to the standard output throught
the FileStream, but I need to redirect it to a string variable. How can I do
it? There is another class like String Stream or I have to implement it?
Thank you for your help.
Original issue reported on code.google.com by [email protected]
on 27 Aug 2012 at 12:32
Steps to reproduce the problem:
1. Try parsing a file without optimizing option, notice everything works fine
2. Enable the highest optimization available (fastest, smallest on Xcode 4.3
LLVM 3.1)
3. Random crashes when parsing the same file as before
That is happening on Mac OSX Lion with Xcode 4.3 with LLVM 3.1 compiler.
I uploaded the same file that i'm using so you can test it and see if you can
reproduce this bug.
We've also experienced some infinite loop while trying to parse a string field
containing an email from facebook API, don't know if it's related, but
disabling the optimization seemed to fix the problem...
Original issue reported on code.google.com by [email protected]
on 3 Sep 2012 at 11:14
Attachments:
https://github.com/lloyd/yajl_vs_rapidjson
This contradicts the results shown in
https://code.google.com/p/rapidjson/wiki/Performance
Original issue reported on code.google.com by [email protected]
on 22 Nov 2011 at 3:31
I have added implementations for std::istream and std::ostream compatible
stream objects for rapidjson. See attached patch.
Original issue reported on code.google.com by [email protected]
on 18 Mar 2012 at 4:35
Attachments:
What steps will reproduce the problem?
1. Compile the library for ARM CPU with optimization
2. Run a simple test that deserializes JSON document
3. The process will core due to SIGBUS signal resulted from misaligned data
access.
What is the expected output? What do you see instead?
The process should not produce SIGBUS signal and core file.
What version of the product are you using? On what operating system?
ARM CPU
Please provide any additional information below.
The cause of the misaligned data access was due to assumptions made in memory
pool class - it has no provisions for allocated memory chunk to be aligned on 4
byte boundary like malloc does in crt allocator rendering library useless if no
changes made to the library for architectures sensitive to data alignment (such
as ARM).
Original issue reported on code.google.com by [email protected]
on 6 Nov 2012 at 3:02
I confirmed that it is a bug. Thank you for reporting.
Original issue reported on code.google.com by xushiweizh
on 6 Dec 2011 at 2:11
What steps will reproduce the problem?
1.rapidjson::GenericDocument<rapidjson::UTF16<>> document;
2.
3.
What is the expected output? What do you see instead?
I've expected work with Unicode String buffer but I had compile error instead
Error was at this place
data_.s.str = (char*)allocator.Malloc(length + 1);
function:
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
RAPIDJSON_ASSERT(s != NULL);
flags_ = kCopyStringFlag;
data_.s.str = (char*)allocator.Malloc(length + 1);
data_.s.length = length;
memcpy((void*)data_.s.str, s, length);
((char*)data_.s.str)[length] = '\0';
}
I changed to
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
RAPIDJSON_ASSERT(s != NULL);
flags_ = kCopyStringFlag;
data_.s.str = (Ch*)allocator.Malloc(length + 1);
data_.s.length = length;
memcpy((void*)data_.s.str, s, length);
((char*)data_.s.str)[length] = '\0';
}
value data_s.str has the Ch* type
What version of the product are you using? On what operating system?
I use the last version from code.google.com. VS2010Prof sp1 compiler WinXP Sp3
system
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 14 Feb 2012 at 7:59
When compiling with GCC 4.7.0 under windows with MinGW/MSYS the following
errors are given:
../../include/rapidjson/document.h: In instantiation of
'rapidjson::GenericDocument<Encoding, Allocator>&
rapidjson::GenericDocument<Encoding, Allocator>::ParseStream(Stream&) [with
unsigned int parseFlags = 1u; Stream =
rapidjson::GenericInsituStringStream<rapidjson::UTF8<> >; Encoding =
rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>;
rapidjson::GenericDocument<Encoding, Allocator> =
rapidjson::GenericDocument<rapidjson::UTF8<> >]':
../../include/rapidjson/document.h:726:54: required from
'rapidjson::GenericDocument<Encoding, Allocator>&
rapidjson::GenericDocument<Encoding,
Allocator>::ParseInsitu(rapidjson::GenericDocument<Encoding, Allocator>::Ch*)
[with unsigned int parseFlags = 0u; Encoding = rapidjson::UTF8<>; Allocator =
rapidjson::MemoryPoolAllocator<>; rapidjson::GenericDocument<Encoding,
Allocator> = rapidjson::GenericDocument<rapidjson::UTF8<> >;
rapidjson::GenericDocument<Encoding, Allocator>::Ch = char]'
JSONLoader.cpp:27:29: required from here
../../include/rapidjson/document.h:706:4: error: 'RawAssign' was not declared
in this scope, and no declarations were found by argument-dependent lookup at
the point of instantiation [-fpermissive]
../../include/rapidjson/document.h:706:4: note: declarations in dependent base
'rapidjson::GenericValue<rapidjson::UTF8<> >' are not found by unqualified
lookup
../../include/rapidjson/document.h:706:4: note: use 'this->RawAssign' instead
../../include/rapidjson/document.h: In instantiation of
'rapidjson::GenericDocument<Encoding, Allocator>&
rapidjson::GenericDocument<Encoding, Allocator>::ParseStream(Stream&) [with
unsigned int parseFlags = 0u; Stream =
rapidjson::GenericStringStream<rapidjson::UTF8<> >; Encoding =
rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>;
rapidjson::GenericDocument<Encoding, Allocator> =
rapidjson::GenericDocument<rapidjson::UTF8<> >]':
../../include/rapidjson/document.h:737:35: required from
'rapidjson::GenericDocument<Encoding, Allocator>&
rapidjson::GenericDocument<Encoding, Allocator>::Parse(const Ch*) [with
unsigned int parseFlags = 0u; Encoding = rapidjson::UTF8<>; Allocator =
rapidjson::MemoryPoolAllocator<>; rapidjson::GenericDocument<Encoding,
Allocator> = rapidjson::GenericDocument<rapidjson::UTF8<> >;
rapidjson::GenericDocument<Encoding, Allocator>::Ch = char]'
JSONLoader.cpp:29:23: required from here
../../include/rapidjson/document.h:706:4: error: 'RawAssign' was not declared
in this scope, and no declarations were found by argument-dependent lookup at
the point of instantiation [-fpermissive]
../../include/rapidjson/document.h:706:4: note: declarations in dependent base
'rapidjson::GenericValue<rapidjson::UTF8<> >' are not found by unqualified
lookup
../../include/rapidjson/document.h:706:4: note: use 'this->RawAssign' instead
Original issue reported on code.google.com by [email protected]
on 9 Jul 2012 at 5:44
I did the following changes:
1) Renamed the unsigned int naming for both uint32_t and uint64_t members, i.e:
a) Member functions
Renamed IsUint() to IsUInt()
Renamed IsUint64() to IsUInt64()
etc.
b) Enums
Renamed kUintFlag to kUIntFlag
Renamed kNumberUint64Flag to kNumberUInt64Flag
etc.
2) Changed the return type of GetUint64() member function from int64_t to
uint64_t because data_.n.u64 is of type uint64_t
3) Added 3 validation member functions: EmptyArray(), EmptyObject(),
EmptyString() , besides the Empty() function that only checks for empty arrays.
This is because there is often the need to check that a certain JSON value
(string, array, object) is empty. It may not be null but empty.
I have utility functions for this and I thought putting the empty part inside
the parser is more appropriate, like the following:
bool IsValidString (const char* name, const Value& value)
{
if (value.HasMember (name) && ! value[name].IsNull()
&& !value[name].EmptyString())
{
return true;
}
return false;
}
bool IsValidArray (const char* name, const Value& value)
{
if (value.HasMember (name) && ! value[name].IsNull()
&& !value[name].EmptyArray())
{
return true;
}
return false;
}
bool IsValidObject (const char* name, const Value& value)
{
if (value.HasMember (name) && !value[name].IsNull()
&& !value[name].EmptyObject())
{
return true;
}
return false;
}
Original issue reported on code.google.com by [email protected]
on 14 Nov 2012 at 2:34
What steps will reproduce the problem?
1. compile the file 'bug.cpp' included below.
2. Seems related to the member template function in a template class, this is
more like my code structure - the first attempt at a bugrep compiled OK though.
3. Tests were on recent Ubuntu, but I first noticed on mingw64 gcc (4.6.1)
What is the expected output? What do you see instead?
Outputs from the compilations included.
What version of the product are you using? On what operating system?
svn r64
Please provide any additional information below.
Seems happy in latest beta Visual Studio. Bit of a blocker though for me.
Original issue reported on code.google.com by [email protected]
on 5 Aug 2012 at 11:07
Attachments:
Parse expressions with custom variables and functions.
Original issue reported on code.google.com by [email protected]
on 26 Nov 2011 at 3:17
I try compile with GCC 4.2 on MacOS and I got error:
integer constant is to large for 'long' type
in this code:
//! Constructor for uint64_t value.
GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
data_.n.u64 = u64;
if (!(u64 & 0x8000000000000000L))
flags_ |= kInt64Flag;
if (!(u64 & 0xFFFFFFFF00000000L))
flags_ |= kUintFlag;
if (!(u64 & 0xFFFFFFFF80000000L))
flags_ |= kIntFlag;
}
Original issue reported on code.google.com by [email protected]
on 25 Jan 2012 at 5:25
Currently, the input and output of Reader uses the same encoding.
It is often needed to read a stream of one encoding (e.g. UTF-8), and output
string of another encoding (e.g. UTF-16). Or in the other way, stringify a DOM
from one encoding (e.g. UTF-16) to an output stream of another encoding (e.g.
UTF-8)
The most simple solution is converting the stream into a memory buffer of
another encoding. This requires more memory storage and memory access.
Another solution is to convert the input stream into another encoding before
sending it to the parser. However, only characters in JSON string type are
really the ones necessary to be converted. Conversion of other characters just
wastes time.
The third solution is letting the parser distinguish the input and output
encoding. It uses an encoding converter to convert characters of JSON string
type. However, since the output length may longer than the original length, in
situ parsing cannot be permitted.
Try to design a mechanism to generalize encoding conversion. And it should
support UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. It can also support
automatic encoding detection with BOM, while incurring some overheads in
dynamic dispatching.
Original issue reported on code.google.com by [email protected]
on 26 Nov 2011 at 4:33
GCC complains about line 92 in writer.h
Level(bool inArray) : inArray(inArray), valueCount(0) {}
Please rename the parameter.
Original issue reported on code.google.com by [email protected]
on 12 Jun 2012 at 10:11
What steps will reproduce the problem?
1. I have the following json text:
{
"type1": 6,
"name": "widget",
"fields": {
"sku": {
"type2": 0,
"value": 5
}
}
}
2. I parse the entire text with no errors and save it as "Document d;"
3. Next when I access the fields of the root object, I get ->
//Make it easier to transfer over as method arg;
const rapidjson::Value *src = &d;
--> if (!src->HasMember("name")) { Error; } // This is ok.
--> const String name((*src)["name"].GetString()); // This is ok.
--> const rapidjson::Value& fields = (*src)["fields"]; // This is ok.
--> if (!fields.IsObject()) { Error; } // This is ok.
--> assert(fields.HasMember("sku")) // This fails.
gdb log for the fields object says:
$25 = (rapidjson::Value &) @0xdd2644: {
data_ = {
s = {
str = 0xdd25e0 "\270", <incomplete sequence \335>,
length = 0,
hashcode = 0
},
n = {
{
i = 14493152,
padding = "\000\000\000"
},
{
u = 14493152,
padding2 = "\000\000\000"
},
i64 = 14493152,
u64 = 14493152,
d = 7.160568503155354e-317
},
o = {
members = 0xdd25e0,
size = 0,
capacity = 0
},
a = {
elements = 0xdd25e0,
size = 0,
capacity = 0
}
},
flags_ = 3,
static kDefaultArrayCapacity = <optimized out>,
static kDefaultObjectCapacity = <optimized out>
}
The size of the members here is 0, but if I try:
for (rapidjson::Value::ConstMemberIterator mIt = fields.MemberEnd();
mIt != fields.MemberBegin();
--mIt) {
const rapidjson::Value::Member& member = *mIt;
}
Here member.name.GetString() returns "type2", which is the inner type(inside
the nested object). Somehow "sku" name is unusable.
What version of the product are you using? On what operating system?
Built on ubuntu 11.10 x64 using both clang and gcc.
I also noticed a similar problem with the array value:
{
"type1" : 7,
"value1" : [
{
"type2" : 5,
"value2" : "a string"
}
]
}
Here when I get value1 using:
const rapidjson::Value& v1 = (*src)["value1"]; // This is ok.
if (!fields.IsArray()) { Error; } // This is ok.
for (rapidjson::Value::ConstValueIterator vIt = v1.End();
vIt != v1.Begin();
--vIt) {
const rapidjson::Value& jsonE = *vIt;
}
Here jsonE value when printed shows that it has no flags, meaning the field
flags_ is 0.
As far as I saw there is some actual content there but the object itself cannot
be tested whether it is an object or not, since it always return false;
Could you please try these samples out.
Thanks,
Petko.
Original issue reported on code.google.com by [email protected]
on 8 May 2012 at 12:48
What steps will reproduce the problem?
1. Create a document jsonDoc ;
2. Assign a value in the document to a new rapidjson::GenericValue<
rapidjson::UTF8<> > newVariable = jsonDoc[ "SomeValue" ]
3. jsonDoc is now null, by design
What is the expected output? What do you see instead?
jsonDoc should refer to the root of the tree.
Original issue reported on code.google.com by [email protected]
on 9 Feb 2012 at 3:05
Hello. I use rapidjson on server part to parse strings which are created on
client side with Flash (ActionScript3) and sometimes (when value become equal
to integer, I suppose) float numbers are written with dot, but without fraction
part, e.i.: {"float_value":123.}
Adobe's JSON parser parses it well, but rapidjson refuses to parse it, so I
made small modifications to continue parsing of such values.
Here is the patch, hope, it is possible to apply it on repository:
===================================================================
--- rapidjson/include/rapidjson/reader.h (revision 64)
+++ rapidjson/include/rapidjson/reader.h (working copy)
@@ -542,20 +542,30 @@
useDouble = true;
}
s.Take();
-
+
+ bool done = false;
+
if (s.Peek() >= '0' && s.Peek() <= '9') {
d = d * 10 + (s.Take() - '0');
--expFrac;
}
else
- RAPIDJSON_PARSE_ERROR("At least one digit in
fraction part", is.Tell());
-
- while (s.Peek() >= '0' && s.Peek() <= '9') {
- if (expFrac > -16) {
- d = d * 10 + (s.Peek() - '0');
- --expFrac;
+ {
+ //some JSON library which I used to form the
database (maybe even rapidjson) written fractional numbers with a dot at end,
so just skip such errors):
+ //RAPIDJSON_PARSE_ERROR("At least one digit in
fraction part", is.Tell());
+ done = true;
+ }
+
+ if ( !done )
+ {
+ while (s.Peek() >= '0' && s.Peek() <= '9')
+ {
+ if (expFrac > -16) {
+ d = d * 10 + (s.Peek() - '0');
+ --expFrac;
+ }
+ s.Take();
}
- s.Take();
}
}
Thank you!
Original issue reported on code.google.com by [email protected]
on 22 Aug 2012 at 5:05
if (name[member->name.data_.s.length] == '\0' &&
memcmp(member->name.data_.s.str, name, member->name.data_.s.length *
sizeof(Ch)) == 0)
return member;
}
This code in document.h line 618 generate segmentation fault on the ARM
architecture.
Problem in the member->name.data_.s.str but I don't know why.
CString at member->name.data_.s.str exist.
Original issue reported on code.google.com by [email protected]
on 31 Jan 2012 at 2:09
This issue was closed by revision r83.
Original issue reported on code.google.com by xushiweizh
on 6 Dec 2011 at 4:06
What steps will reproduce the problem?
1. Use CrtAllocator instead of MemoryPoolAllocator.
2. Add values to objects or arrays.
What is the expected output? What do you see instead?
It should add values normally.
But sometimes segmentation fault occur.
The problem exists in the AddMember() and PushBack() methods of GenericValue.
They allocate memory and then assign new values into that memory.
This assignment is overloaded and calls the destructor on uninitialized data
before copying the new values.
The destructor checks if kNeedFree is true and then tries to determine the
specific type of the value and if it has to free more memory recursively.
There is no problem with MemoryPoolAllocator because it has kNeedFree on false
and so the destructor has nothing to do.
I think the assignment operators in AddMember() and PushBack() should replaced
by RawAssign() method which doesn't call the destructor.
I added a patch file.
Original issue reported on code.google.com by [email protected]
on 30 Sep 2012 at 6:21
Attachments:
What steps will reproduce the problem?
1. try to remove last member in JSON entry by calling
object.RemoveMember("lastentry");
What is the expected output? What do you see instead?
Expected would be that this given member would be removed like the others.
What happens is that it crashes because it tries to remove last member by
moving the last one to it's place :)
this assert on line 165 in document.h crashes it:
RAPIDJSON_ASSERT(this != &rhs);
What version of the product are you using? On what operating system?
0.1 version
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 31 Jul 2012 at 12:22
String in JSON are not validated to be UTF-8 or UTF-16. The parser do not
detect whether the string contain invalid encoding.
Both YAJL and ultrajspon supports UTF-8 validation. YAJL can turn it on/off,
while ultrajson make it mandatory.
Add an parsing option to validate UTF-8/UTF-16.
Original issue reported on code.google.com by [email protected]
on 22 Nov 2011 at 2:40
What steps will reproduce the problem?
1. Include the headers in a cpp file.
2. Try to compile it with the Embarcadero command line compiler.
What is the expected output? What do you see instead?
Expecting to see it compile. Instead, it failed to compile giving several
error messages.
...
Error E2450 include\rapidjson/document.h 30: Undefined structure
'GenericValue<Encoding,Allocator>'
Error E2449 include\rapidjson/document.h 30: Size of 'name' is unknown or zero
Error E2450 include\rapidjson/document.h 31: Undefined structure
'GenericValue<Encoding,Allocator>'
Error E2449 include\rapidjson/document.h 31: Size of 'value' is unknown or zero
...
What version of the product are you using? On what operating system?
Version 0.1 on Windows 7
Please provide any additional information below.
I've tried in the ancient 5.5 version of the compiler by Borland and the new
one from Embarcadero.
Original issue reported on code.google.com by [email protected]
on 29 Mar 2012 at 5:14
Hi, I really like this lib but I am facing an issue.
I have in my json files a huge array of doubles that, when written with
PrettyWriter, it is displayed with each item separated by a newline.
I'd like to set PrettyWriter in a way that I can print that array on a single
line. Is that possible?
Thanks
Original issue reported on code.google.com by [email protected]
on 7 Mar 2012 at 1:34
What steps will reproduce the problem?
rapidjson::Document doc;
doc.Parse<0>(std::string::jsonIn.c_str());
if (doc.HasParseError())
{
cerr << "ERROR: " << doc.GetParseError() << endl;
}
What is the expected output? What do you see instead?
"ERROR: Unknown escape character"
What version of the product are you using? On what operating system?
0.11
Please provide any additional information below.
JSON:
{
"DataDir":"E:\Something"
}
Original issue reported on code.google.com by [email protected]
on 7 Dec 2012 at 10:18
Is there a demo showing how to use the SAX parsing capability of rapidjson?
I searched through the examples but can't find a thing and I can't understand
how to do it just by reading the rapidjson source code.
If someone is willing please add an example of how to do SAX parsing with
rapidjson.
Original issue reported on code.google.com by [email protected]
on 29 Aug 2012 at 8:40
What steps will reproduce the problem?
1. Compile with gcc 4.7.2 using -Werror=cast-qual
What version of the product are you using? On what operating system?
rapidjson 0.1.
Please provide any additional information below.
In the destructor ~GenericValue() there is a line like this:
Allocator::Free((void*)data_.s.str);
That line seems wrong - It casts away const.
The minimal fix (assuming that the logic is otherwise correct) is to change
this to:
Allocator::Free(const_cast<void*>((const void*)data_.s.str));
Original issue reported on code.google.com by [email protected]
on 14 Nov 2012 at 12:05
What steps will reproduce the problem?
1. Make a document.
2. use ParseInsitu to parse.
3. compile gcc -O3 -Wall
What is the expected output? What do you see instead?
no warnings. I see reader.h:617: error: 'd' may be used uninitialized in this
function
reader.h:556: error: 'i64' may be used uninitialized in this function.
What version of the product are you using? On what operating system?
0.1, Linux, gcc 4.6.2 -O3 -Wall
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 22 Feb 2012 at 10:57
What steps will reproduce the problem?
1. Decode number field < int32_max {"bar" : 1596811002 }
2. Decode number field > int32_max with bit 0x80000000 set {"bar" : 2740789000 }
3. Attempt to extract both fields from document as Int64()
What is the expected output? What do you see instead?
Expected output is correctly parsing to int64_t in both cases. Actual behavior
is an Assert that the second case does not have the kInt64Flag.
Set flags in this case include kNumber, kInt, and kUint.
What version of the product are you using? On what operating system?
0.1
Please provide any additional information below.
The error is at line 80 of rapidjson/document.h:
if (!(u & 0x80000000))
flags_ |= kIntFlag | kInt64Flag
I've fixed it locally by changing the code to this:
GenericValue(unsigned u) : flags_(kNumberUintFlag) {
data_.n.u64 = u;
if (!(u & 0x80000000))
flags_ |= kIntFlag;
flags_ |= kInt64Flag;
}
I didn't attach a patch due to the small scope of the change, but would be
happy to if you'd like.
Original issue reported on code.google.com by [email protected]
on 15 Oct 2012 at 8:34
What steps will reproduce the problem?
1. create UTF8 file using ordinary text editor (Nodepad++). By default it is
created with BOM.
2. load file as raw binary file
3. pass to rapidjson Document to parse
Parsing fails with error "Expect either an object on array at root".
Original issue reported on code.google.com by [email protected]
on 8 Jun 2012 at 8:16
What steps will reproduce the problem?
1. compile and run the simple attached program
2.
3.
What is the expected output? What do you see instead?
No output, just successful completion. Memory corruption on free().
What version of the product are you using? On what operating system?
Recent, Linux.
Please provide any additional information below.
I think perhaps operator= should be private?
Original issue reported on code.google.com by [email protected]
on 25 Apr 2012 at 7:32
Attachments:
Object member access, i.e. Value::FindMember(), is in O(n) by linear searching.
Design a faster approach for member access.
Original issue reported on code.google.com by [email protected]
on 30 Nov 2011 at 5:31
Milo,
This is a great lib. We inspected many JSON libs for parsing purpose and
rapidjson is the fastest one.
However, since we need to build on multiple platforms (Linux, Sun, AIX, MS
Windows) with multiple compilers(GCC, SunCC, XlC, MSVC), it would be even nicer
if some of the "MS specific" extensions can be removed.
1. In document.h, Number is defined as
#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
struct {
int i;
char padding[4];
};
struct {
unsigned u;
char padding2[4];
};
#else
struct {
char padding[4];
int i;
};
struct {
char padding2[4];
unsigned u;
};
#endif
Anonymous struct is used here, which is an MS extension.
GCC by default (without -fms-extension flag) will issue an compilation error.
Meanwhile, you made assumptions sizeof(int) == 4 here, which is not always the
case. One possible solution will be using uint64_t and int64_t for everything
and let the compiler handle typecasting (which is extremely cheap on integers)
2. Line 407 of reader.h
if ((sizeof(Ch) == 1 || e < 256) && escape[(unsigned char)e])
GCC will issue a warning:
reader.h:407: warning: comparison is always true due to limited range of data
type
Since e is type Ch, which is instantiated by the template as (char), and char
is always smaller than 256.
3. pack(push, <number>) and pack(pop) are not supported by all the compilers.
However, I have no perfect alternative on how to solve the problem.
On our case, we change it to pack(<number>) and pack(), which will reset the
alignment to the compiler default, but that will not work correctly if you
already have content in the alignment stack.
Thanks
Biye
Original issue reported on code.google.com by [email protected]
on 27 Apr 2012 at 5:02
I want to create an new json document:
========================================
rapidjson::Document document;
document.AddMember<int>("int_1", 1, document.GetAllocator());
========================================
Program asserted at document.h:253
252: GenericValue& AddMember(GenericValue& name, GenericValue& value,
Allocator& allocator) {
253: RAPIDJSON_ASSERT(IsObject());
I must call Parse("{}") before any AddMember() to avoid this assert.
It's corrected?
Original issue reported on code.google.com by [email protected]
on 11 Oct 2012 at 6:51
What steps will reproduce the problem?
1. Add rapidjson headers to xcode project.
2. Compile with LLVM 4.0 and xcode 4.4
What is the expected output?
Compile without errors.
What do you see instead?
Error in Document.h line 704:
"if (reader.Parse<parseFlags>(is, *this)) {"
"Semantic Issue: Reference to non-static member function must be called."
What version of the product are you using?
SVN version 18.
On what operating system?
OSX 10.7.4 with Xcode 4.4 and Apple LLVM 4.0
Please provide any additional information below.
It compiles without error using LLVM GCC 4.2
Original issue reported on code.google.com by [email protected]
on 26 Jul 2012 at 1:45
What steps will reproduce the problem?
1. Use a StringBuffer for the output stream with a Writer
2. When grabbing the string, make a std::string(buf.GetString(), buf.Size())
3.
What is the expected output? What do you see instead?
This should compile and build a std::string with the buffer's contents copied
into it. Instead, the code fails to compile. internal::Stack does not have a
member function Size(), but rather GetSize().
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 22 Feb 2012 at 9:59
Version 0.1 and trunk
return type of GetUint64() is int64_t.
The correct return type is uint64_t.
Original issue reported on code.google.com by [email protected]
on 15 Nov 2012 at 2:57
Issue discovered from
http://stackoverflow.com/questions/13200191/stringify-with-rapidjson
It is due to GenericValue::Accept() is not const.
As GenericValue::Accept() just generates events for handler, it does not need
to modify the value and its decedents. So it should change from:
template <typename Handler>
GenericValue& Accept(Handler& handler)
to
template <typename Handler>
const GenericValue& Accept(Handler& handler) const
Original issue reported on code.google.com by [email protected]
on 14 Nov 2012 at 7:13
I understand the main purpose of rapidjson is to comply exactly to JSON RFC,
but in some case, using rapidjson to parse 'javascript object syntax' would be
usefull too.
I'm not an expert, but afaik the main differences I see are:
1- key of each attribute may not be sourrounded with quote
2- string quotes can be both simple quote (') or double quote ("). In case of
double quote, the simple quote has not to be escaped, and in case of simple
quote, the double quote has not to be escaped.
3- there are constraints on key names (no whitespace in them, not beginning
with a digit, ...)
That way, a string like the following would become parsable without error:
{ a:'titi', b:27, bcd :[1,2], abc : {x:12,y:12,z: 12 } }
I did a first try covering points 1 and 2 above ; you'll find it as attachement
(only reader.h has been patched). It's just a try, nothing polised here. For
example, a flag should obviously be added in the parser to allow (or not) such
'relaxed' syntax and there are probably performance caveheats.
BTW, really nice lib ; thanks for sharing :-)
Original issue reported on code.google.com by [email protected]
on 4 Sep 2012 at 8:42
Attachments:
This code in writer.h isn't universal:
#if _MSC_VER
int ret = sprintf_s(buffer, sizeof(buffer), "%g", d);
#else
int ret = snprintf(buffer, sizeof(buffer), "%g", d);
#endif
I create app for mobile platform with MarmaladeSDK and I have cstdio.h
without sprintf_s, because I work in VisualStudio my project don't build with
this.
Original issue reported on code.google.com by [email protected]
on 24 Jan 2012 at 6:04
What steps will reproduce the problem?
1. Make a document and set it via SetNull()
2. try to write the document with a Writer
3.
What is the expected output? What do you see instead?
I would expect some recovery mechanism; If we encounter such a malformed case,
we need to gracefully handle the problem (i.e. we cannot crash)
What version of the product are you using? On what operating system?
0.1. Linux.
Please provide any additional information below.
Some of these asserts are down deep in the code. The current design is not
geared toward return codes. My suggestion would be to throw an exception when
malformed documents are encountered.
Original issue reported on code.google.com by [email protected]
on 22 Feb 2012 at 10:18
What steps will reproduce the problem?
1. compile with gcc (eg 4.4.3) with -pedantic
What version of the product are you using? On what operating system?
0.11
Please provide any additional information below.
In rapidjson.h, there is one comma after the final field in the enum 'Type'.
This is not allowed in C++98:
http://code.google.com/p/rapidjson/source/browse/trunk/include/rapidjson/rapidjs
on.h?r=131#251
Solution:
kNumberType = 6, //!< number
should be changed to
kNumberType = 6 //!< number
Original issue reported on code.google.com by [email protected]
on 7 Dec 2012 at 9:47
What steps will reproduce the problem?
1. use UTF16 document
2. use Parse, not ParseInsitu
3. == string corruption on simple JSON sample
std::wstring test2(L"[{\"created_at\":\"Wed Oct 30 17:13:20 +0000 2012\"}]");
GenericDocument< UTF16LE<> > json;
json.Parse<kParseValidateEncodingFlag>(test2.c_str());
This is due to a bug in SetStringRaw() - it does not take account of the size
of multi-byte strings when allocating and copying, thus when used with wchar_t,
the string data gets chopped in half.
The following two changes seem to fix things:
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
RAPIDJSON_ASSERT(s != NULL);
flags_ = kCopyStringFlag;
>> data_.s.str = (Ch *)allocator.Malloc((length + 1) * sizeof(Ch));
data_.s.length = length;
>> memcpy((void*)data_.s.str, s, (length * sizeof(Ch)));
((Ch*)data_.s.str)[length] = '\0';
}
Original issue reported on code.google.com by [email protected]
on 7 Nov 2012 at 11:40
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.