gpt4 book ai didi

c++ - RESTful API、C++restSDK、C++ 中的 JSON

转载 作者:行者123 更新时间:2023-11-30 05:02:55 24 4
gpt4 key购买 nike

我正在尝试使用这个 RESTful API:https://github.com/binance-exchange/binance-official-api-docs/blob/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。根据 Binance 文档:

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 执行 GET 请求,然后让我的 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;
}
}

关于c++ - RESTful API、C++restSDK、C++ 中的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49618320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com