Skip to content
JsonData

Parse

void Parse(const std::string jsonCode)

Will attempt to parse jsonCode, and set itself to the result.
This can throw a LOT of different exceptions, mostly related to faulty json-syntax in jsonCode.

Use IsJsonValid() to check this.

This action will completely overwrite this JsonData object.


The json code supplied does not have to be minified.

Example

std::string code = "{\"name\":\"Peter Griffin\",\"age\":58,\"kids\":[\"Stewie\",\"Chris\",\"Megatron\"]}";

Json json;
json.Parse(code);

// This std::cout is just to demonstrate that it parsed successfully.
std::cout << json["name"] << " is " << json["age"]
          << " years old and has " << json["kids"].AsArray.Size()
          << " kids." << std::endl;