Skip to content

oblerion/JsonObject.hpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Translate of JsonObject.cs for c++.
With same functionnality and fix.

How use it

your json file

{
"x":5, "size": 0.5, "name":"jake", "point":{"x":12, "y":34}, 
"visible":true, "array":[0,2,4]
}

your code

#include "JsonObject.hpp"
#include <string>
#include <vector>

JsonObject jo("file.json");
if(jo.IsEmpty()==false)
{
  int x = jo.GetInt("x");            //-> 5
  float size = jo.GetFloat("size");  //-> 0,5
  std::string name = jo.GetString("name");//-> jake
  int point_x = jo.GetObject("point").GetInt("x"); // -> 12
  int point_y = jo.GetObject("point").GetInt("y"); // -> 34
  bool visible = jo.GetBool("visible"); //-> true
  std::vector<int> arr = jo.GetArray("array");
}