Getting value from json-spirit

I use the Json-Spirit library, however I'm not sure how to read the value from the object, without repeating each pair of names.

If I have an object such that:

{ "boids": { "width": 10, "count": 5, "maxSpeedMin": 2, "maxSpeedMax": 80, "maxForceMin": 0.5, "maxForceMax": 40 } } 

How can I access, for example, the width value by name?

+4
source share
2 answers

json_spirit added support for std :: map so you can find the value.

One of the projects in json_spirit download is json_map_demo. This will help you better understand this.

+4
source

It is possible.

Sample code below.

 string test = { "boids": { "width": 10, "count": 5, "maxSpeedMin": 2, "maxSpeedMax": 80, "maxForceMin": 0.5, "maxForceMax": 40 } } mValue value; if(read(test, value)) { mObject obj = value.get_obj(); obj = obj.find("boids")->second.get_obj(); /*Now the obj would contain the sub object,that is {"width": 10, "count": 5, "maxSpeedMin": 2, "maxSpeedMax": 80, "maxForceMin": 0.5, "maxForceMax": 40 } */ int nWidth = obj.find("width")->second.get_int(); 
+3
source

Source: https://habr.com/ru/post/1342520/


All Articles