Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert json value to int in c++

Tags:

c++

json

I'm reading a json value in c++ using

Json::Reader reader

and the value is stored in Json::Value root

This root contains "age" and "id" and I want to convert root["age"] to int.

I tried to convert it to string using .str() but could not get.

Any suggestion?

like image 230
rocx Avatar asked Oct 31 '13 13:10

rocx


1 Answers

In jsoncpp they provide helper methods on the Json::Value object. You can merely call the asInt() method on the value to convert it.

int ageAsInt = root["age"].asInt()
like image 195
Mark Loeser Avatar answered Oct 06 '22 00:10

Mark Loeser