@@ -109,19 +109,13 @@ PHP_METHOD(rapidjson, __construct) /* {{{ */ {
109
109
return ;
110
110
}
111
111
112
- // printf("Original JSON:\n %s\n", json);
113
-
114
- Document document; // Default template parameter uses UTF8 and MemoryPoolAllocator.
115
-
116
- // In-situ parsing, decode strings directly in the source string. Source must be string.
117
- // char buffer[sizeof(json)];
118
- // memcpy(buffer, json, sizeof(json));
119
- if (document.ParseInsitu (json).HasParseError ()) {
112
+ Document *document = new Document ();
113
+ if (document->Parse (json).HasParseError ()) {
120
114
printf (" \n Parsing error\n " );
121
115
return ;
122
116
}
123
117
self = getThis ();
124
- zdoc.value .ptr = & document;
118
+ zdoc.value .ptr = document;
125
119
zend_update_property (rapidjson_ce, self, ZEND_STRL (" obj" ), &zdoc);
126
120
127
121
}
@@ -159,14 +153,25 @@ PHP_METHOD(rapidjson, offsetGet) /* {{{ */ {
159
153
obj = zend_read_property (rapidjson_ce, self, ZEND_STRL (" obj" ), 1 , NULL );
160
154
Document *document;
161
155
document = (Document *)obj->value .ptr ;
162
-
163
156
if (!document->HasMember (offset->value .str ->val )) {
164
157
RETURN_NULL ();
165
158
return ;
166
159
}
167
- const char *val = (*document)[offset->value .str ->val ].GetString ();
168
- zend_string *ret = zend_string_init (val, strlen (val), 0 );
169
- RETURN_STR (zend_string_copy (ret));
160
+ const Value& val = (*document)[offset->value .str ->val ];
161
+ if (val.IsString ()) {
162
+
163
+ zend_string *ret = zend_string_init (val.GetString (), strlen (val.GetString ()), 0 );
164
+ RETURN_STR (zend_string_copy (ret));
165
+ }
166
+ if (val.IsInt () || val.IsUint () || val.IsInt64 () || val.IsUint64 ()) {
167
+ RETURN_LONG (val.GetUint64 ());
168
+ }
169
+ if (val.IsDouble ()) {
170
+ RETURN_DOUBLE (val.GetDouble ());
171
+ }
172
+ if (val.IsBool ()) {
173
+ RETURN_BOOL (val.GetBool ());
174
+ }
170
175
}
171
176
/* }}} */
172
177
0 commit comments