Permalink
Browse files

Fix issue #24

  • Loading branch information...
1 parent 261fca3 commit a41b76b339ab4b925b3a3d28aa0e91e310bc3453 @YasserAsmi committed Feb 7, 2016
Showing with 42 additions and 4 deletions.
  1. +2 −2 README.md
  2. +35 −1 example/misc.cpp
  3. +5 −1 src/json.cpp
View
@@ -7,8 +7,8 @@ In particular, it implements a Variant type which is similar to 'var' in JS. Li
The Variant, combined with JSON and simple automatic memory management, makes for a very powerful data structure even in C++.
jvar is designed to be very fast. Because the backing data structures are optimized, JSON parsing speed is very fast. Special attention has been paid to how often things are copied and how often memory is allocated.
-jvar doesn't use have any dependencies. It doesn't use Boost and hardly uses STL. It only uses std::string--but even with that jvar tries to minimize memory allocations. Some C++11 features are optionally (via build option) used to provide more easy of use.
-
+jvar doesn't use have any dependencies. It doesn't use Boost and hardly uses STL. It only uses std::string--but even with that jvar tries to minimize memory allocations. Some C++11 features are optionally (via build option) used to provide more ease of use.
+
Please take a look at the examples to see if you agree with the added expressiveness.
Build! Go!
View
@@ -146,9 +146,43 @@ void bugreport2()
testParse("name(");
}
+void bugreport3()
+{
+ const char *test = ""
+"{"
+" \"cmd\":\"sdata.json\","
+" \"arg_s\":1,"
+" \"time\":191451698,"
+" \"ybase\":2010,"
+" \"arg_m\":\"3\","
+" \"irms\":[5.8,0.0,0.0,0.0],"
+" \"vrms\":[121.8,0.1,0.1],"
+" \"watt\":[693.6,0.0,0.0],"
+" \"va\":[700.2,0.0,0.0],"
+" \"var_\":[-95.9,0.0,-0.0],"
+" \"power\":693.6,"
+" \"angle\":[172.1,119.9,140.4],"
+" \"period\":16668.0,"
+" \"freq\":59.0,"
+" \"energy\":42562362,"
+" \"watthr\":[42562362,0,0],"
+" \"vahr\":[46962595,0,0],"
+" \"varhr\":[-6319438,0,0],"
+" \"fwatthr\":[42668693,0,0],"
+" \"fvarhr\":[-6211040,0,0],"
+" \"energy\":9999999,"
+" \"emul\":2.608076793215e-03"
+"}";
+
+ Variant array;
+ array.parseJson(test);
+
+ puts(array.toString().c_str());
+}
+
int main(int argc, char** argv)
{
showFormat();
showArray();
- bugreport2();
+ bugreport3();
}
View
@@ -84,7 +84,11 @@ void JsonParser::parseMembers(Variant& var)
}
advance(':');
- Variant& newprop = var.addProperty(key.c_str());
+ // Issue #24: addOrModifyProperty() allows duplicate properties to be added
+ // in the array. While JSON standard don't say what the right behavior is, jvar
+ // follows the JavaScript behavior and the value is set to the very last value set.
+
+ Variant& newprop = var.addOrModifyProperty(key.c_str());
parseValue(newprop);

0 comments on commit a41b76b

Please sign in to comment.