-1

I'm writing C++ code using curl and JsonCpp (https://github.com/open-source-parsers/jsoncpp). Json::parseFromStream returns the following data:

Funds: [
        {
                "id" : 1,
                "jsonrpc" : "2.0",
                "result" :
                {
                        "availableToBetBalance" : 437.91000000000003,
                        "discountRate" : 4.0,
                        "exposure" : 0.0,
                        "exposureLimit" : -5000.0,
                        "pointsBalance" : 3135,
                        "retainedCommission" : 0.0,
                        "wallet" : "UK"
                }
        }
]

How do I extract availableToBetBalance - I've tried things like:

std::string d = json_data["result.availableToBetBalance"].asString();

and:

std::string d = json_data["result"]["availableToBetBalance"].asString();

The latter throws and exception : in Json::Value::resolveReference(key, end): requires objectValue

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Steve
  • 11
  • 4

1 Answers1

0

You're ignoring the array layer, signified by the outer [ and ] characters.

In this particular case, the data you're looking for is in the first (and only) element of an array, so:

std::string d = json_data[0]["result"]["availableToBetBalance"].asString();
//                       ^^^
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055