diff --git a/rapidjson.cpp b/rapidjson.cpp index b7391be..e612970 100644 --- a/rapidjson.cpp +++ b/rapidjson.cpp @@ -183,16 +183,16 @@ PHP_METHOD(rapidjson, offsetSet) /* {{{ */ { obj = zend_read_property(rapidjson_ce, self, ZEND_STRL("obj"), 1, NULL); Document *document; - document = (Document *)obj->value.ptr; + document = (Document *)obj->value.ptr; if (!document->HasMember(key->val)) { RETURN_NULL(); return; } - Value& val = (*document)[key->val]; - + Value& val = (*document)[key->val]; + if (IS_STRING == Z_TYPE_P(value)) { - val.SetString(StringRef(Z_STRVAL_P(value), Z_STRLEN_P(value))); + val.SetString(Z_STRVAL_P(value), Z_STRLEN_P(value)); } else if (IS_LONG == Z_TYPE_P(value)) { val.SetInt64(Z_LVAL_P(value)); } else if (IS_NULL == Z_TYPE_P(value)) { diff --git a/tests/001.phpt b/tests/001.phpt index a72c35e..89cac77 100644 --- a/tests/001.phpt +++ b/tests/001.phpt @@ -7,9 +7,9 @@ Check for rapidjson get value and toString $str = '{"author":"Jason Young"}'; $obj = new Rapidjson($str); echo $obj; +echo "\n"; var_dump($obj['author']); ?> --EXPECT-- -{ - "author": "Jason Young" -}string(11) "Jason Young" +{"author":"Jason Young"} +string(11) "Jason Young" diff --git a/tests/002.phpt b/tests/002.phpt index 497d634..c574e24 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -11,6 +11,4 @@ echo $obj; ?> --EXPECT-- string(11) "Jason Young" -{ - "author": "Jason Young" -} +{"author":"Jason Young"} \ No newline at end of file diff --git a/tests/003.phpt b/tests/003.phpt index a4d2936..eab1ff2 100644 --- a/tests/003.phpt +++ b/tests/003.phpt @@ -11,15 +11,20 @@ $obj->parse($str); var_dump($obj['author']); $obj['author'] = "Yangshengjie"; var_dump($obj['author']); +echo $obj; +echo "\n"; var_dump($obj['age']); -$obj['age'] = "23"; +$obj['age'] = 24; var_dump($obj['age']); +echo $obj; +echo "\n"; ?> --EXPECT-- string(11) "Jason Young" string(12) "Yangshengjie" +{"author":"Yangshengjie","age":23} int(23) -string(2) "23" - +int(24) +{"author":"Yangshengjie","age":24}