Reputation: 75
I am trying to use THIS RESTful API: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
To do this, I am using THIS C++ SDK: https://github.com/Microsoft/cpprestsdk
The Binance API returns everything as JSON, which is where I think my issue lies.
My code is here: https://pastebin.com/SeBAxvA0
I think the error is here in this function (commented as well in pastebin):
void print_test(json::value const & value){
if(!value.is_null()){
//I am doing something wrong here I'm pretty sure.
auto response = value[L"responseData"];
//"responseData" is probably not what should be here I think?
auto results = response[L"serverTime"];
wcout << results.as_integer() << endl;
}
}
Basically, I am trying to just test out this API by doing a simple GET method for the server time from the Binance API. According to the Binance documentation:
Check server time
GET /api/v1/time
Test connectivity to the Rest API and get the current server time.
Weight: 1
Parameters: NONE
Response:
{
"serverTime": 1499827319559
}
So I would like to do a GET request for that JSON, and then have my C++ program output the value of serverTime. When I try to run my code as is, I get an error saying:
error: no viable overloaded operator[] for type
'const json::value'
auto response = value[L"responseData"];
However, I am following along with an example from the C++restSDK found here: http://mariusbancila.ro/blog/2013/08/02/cpp-rest-sdk-in-visual-studio-2013/
I think my issue has something to do with the two lines under the comment I made on line 45 in my pastebin. Presumably, I am assigning the wrong values to one or both of the variables under that line. I know this is a pretty specific help request, but does anyone know what I'm doing wrong and how to get the value of serverTime to display?
Upvotes: 1
Views: 1516
Reputation: 75
I solved this issue on my own after much digging :) Error was in this function and it is now fixed with this code:
void print_test(json::value const & value){
if(!value.is_null()){
json::value test = value;
cout << test["serverTime"] << endl;
}
}
Upvotes: 1