RESTful API, C++restSDK, JSON in C++
RESTful API, C++restSDK, JSON in C++
我正在尝试使用此RESTFUL API:https://github.com/binance-exchange/binance-incial-api-api-docs/blob/master/master/rest-api.md
为此,我正在使用此C SDK:https://github.com/microsoft/cpprestsdk
Binance API返回所有内容,如JSON,这是我认为我的问题所在的地方。
我的代码在这里:https://pastebin.com/sebaxva0
我认为错误在此功能中(在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;
}
}
基本上,我试图通过从Binance API为服务器时间进行简单的GET方法来测试此API。根据二元文档:
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
}
因此,我想对该JSON提出一个请求,然后让我的C 程序输出Servertime的值。当我尝试按原样运行代码时,我会发现一个错误说:
error: no viable overloaded operator[] for type
'const json::value'
auto response = value[L"responseData"];
但是,我正在跟随C RESTSDK的示例,此处找到:http://mariusbancila.ro/blog/2013/08/02/cpp-rest-sdk-in-visual-studio-2013/
我认为我的问题与我在Pastebin上的第45行所作的评论下的两行有关。据推测,我将错误的值分配给该行下的一个或两个变量。我知道这是一个非常具体的帮助请求,但是有人知道我在做什么错以及如何使Servertime的价值显示?
我在大量挖掘后自己解决了这个问题:)错误是在此函数中,现在已使用此代码固定:
void print_test(json::value const & value){
if(!value.is_null()){
json::value test = value;
cout << test["serverTime"] << endl;
}
}
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp