title: using json spirit to read the name and value of Value objects in C++
body: <p>I have a text file that's got data written in JSON format.
  The data looks something like this -- </p>
  
  <pre><code>[
     ...
      {
      "volume": 93, 
      "id": "part-30", 
      "value": 19
    }, 
    {
      "volume": 83, 
      "id": "part-31", 
      "value": 19
    }
    ...
  ]
  </code></pre>
  
  <p>After referring to <a href="https://github.com/png85/json_spirit/blob/master/README.md" rel="nofollow noreferrer">this</a> and <a href="https://stackoverflow.com/questions/16827508/using-json-spirit-to-read-json-string-in-c">this</a></p>
  
  <p>I've gotten to a point where I can read the "name" field of the following data structure. 
  So all other things aside, my code to read this object looks like this -- </p>
  
  <pre><code>// read from parts list file to JSON object.
      const char* file_name2( "parts_list.txt" );
      ifstream is2( file_name2 );
      json_spirit::Value value2;
      read( is2, value2 );
      // const Object&amp; addr_array = value.get_obj();
      vector&lt;Value&gt; jsonObj2 = value2.get_array();
      vector&lt;Value&gt;::iterator it;
      vector&lt;RobotParts&gt; final;
  
      for(it = jsonObj2.begin(); it!=jsonObj2.end(); it++)
      {
          auto valObj = it-&gt;get_obj();
          RobotParts rpObj = RobotParts();
          for(auto vo : valObj)
          {
              if(vo.name_=="volume"){
                  string s = vo.value_;
              }
          }
          final.push_back(rpObj);
      }
  
      cout &lt;&lt; final.size() &lt;&lt; endl;
      return 0;
  </code></pre>
  
  <p>But this line here --> <code>vo.value_;</code> seems to be creating a lot of problems.
  I'm unable to figure out what's the data type of this object.
  So far I've tried :</p>
  
  <ol>
  <li>Reading into an integer. I thought since the volume has an integer value</li>
  </ol>
  
  <blockquote>
    <p>int i = vo.get_value&lt; int >();</p>
  </blockquote>
  
  <p>Should work. But instead, it says </p>
  
  <pre><code>error: no member named 'get_value' in
    'json_spirit::Pair_impl&lt;json_spirit::Config_vector&lt;std::__1::basic_string&lt;char&gt; &gt; &gt;'
  </code></pre>
  
  <ol start="2">
  <li>Reading into a string so I could print it out. </li>
  </ol>
  
  <blockquote>
    <p>string s = vo.value_;</p>
  </blockquote>
  
  <p>This throws the following error:</p>
  
  <pre><code>error: no viable conversion from 'Value_type' (aka
        'Value_impl&lt;json_spirit::Config_vector&lt;std::__1::basic_string&lt;char&gt; &gt; &gt;') to 'string' (aka 'basic_string&lt;char, char_traits&lt;char&gt;,
        allocator&lt;char&gt; &gt;')
  </code></pre>
  
  <p>I can, however, print out vo.name_ by using <code>cout &lt;&lt; vo.name_ &lt;&lt; endl</code> within the loop.
  This outputs :</p>
  
  <pre><code>...
  volume
  id
  value
  volume
  id
  value
  ... 
  </code></pre>
  
  <p>so on.</p>
  
  <p>I know this is due to data type incompatibility but I've spent two-three hours now unable to figure out how to access this value.</p>
  
  <p>How do I access these values corresponding to volume, id and value?</p>