JsonArray.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "JsonArray.h"
  2. #include "JsonValue.h"
  3. JsonValue JsonArray::operator[](int index) const
  4. {
  5. for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
  6. {
  7. if (!index) return JsonValue(*it);
  8. index--;
  9. }
  10. return JsonValue();
  11. }
  12. void JsonArray::add(bool value)
  13. {
  14. JsonNode* node = createNode(JSON_BOOLEAN);
  15. if (!node) return;
  16. node->content.asBoolean = value;
  17. addChild(node);
  18. }
  19. void JsonArray::add(char const* value)
  20. {
  21. JsonNode* node = createNode(JSON_STRING);
  22. if (!node) return;
  23. node->content.asString = value;
  24. addChild(node);
  25. }
  26. void JsonArray::add(double value, int decimals)
  27. {
  28. JsonNode* node = createNode((JsonNodeType)(JSON_DOUBLE_0_DECIMALS + decimals));
  29. if (!node) return;
  30. node->content.asDouble = value;
  31. addChild(node);
  32. }
  33. void JsonArray::add(long value)
  34. {
  35. JsonNode* node = createNode(JSON_INTEGER);
  36. if (!node) return;
  37. node->content.asInteger = value;
  38. addChild(node);
  39. }