小编use*_*144的帖子

从.txt文件美化C ++中的JSON字符串

我目前在C ++中工作,使用ostream从我写入.txt文件的请求中获取HTTP响应。这是异步发生的,我不想更改它。

数据写完后,我想从文件中读取

{"data":{"request":[{"type":"City","query":"London, United Kingdom"}],"weather":[{"date":"2013-04-21","astronomy".....

〜以某种方式〜使用外部库(例如nlohmann / json或other(?))对字符串进行美化,然后

a)将其打印到控制台,然后b)将其保存在其他文件(pretty.json)中

我无法理解从以下哪种方法使用:https : //github.com/nlohmann/json

任何想法如何解决这个问题?

我一直在想逐行获取文件,直到将EOF打入某种“缓冲区”,然后在该文件上运行_json并保存可以在控制台上显示的解决方案...

到目前为止我的代码

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <iostream>
#include <sstream>
#include "json.hpp"



using namespace utility;                // string conversion
using namespace web;                    // URI 
using namespace web::http;              // HTTP commands
using namespace web::http::client;      // HTTP Client features
using namespace concurrency::streams;   // Asynch streams, like Node

using json = nlohmann::json;

int main()
{
auto fileStream = std::make_shared<ostream>();

// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.txt")) …
Run Code Online (Sandbox Code Playgroud)

c++ json asynchronous nlohmann-json

2
推荐指数
1
解决办法
2616
查看次数

标签 统计

asynchronous ×1

c++ ×1

json ×1

nlohmann-json ×1