-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Hello, I have unfortunately a problem with which I come no further:
I have data in the form of a list of multiple objects and I want to create json :: array's from it.
Input:
{ "candles":[ { "close":"470.0380", "epoch":1489306680, "high":"470.0954", "low":"469.8577", "open":"469.8577" }, { "close":"469.3634", "epoch":1489306740, "high":"470.0012", "low":"469.2554", "open":"470.0012" }, { "close":"469.4181", "epoch":1489306800, "high":"469.6009", "low":"469.1578", "open":"469.3178" } ], "echo_req": { "count":3, "end":"latest", "style":"candles", "ticks_history":"R_50" }, "msg_type":"candles" }
I would like the following output:
{ "open": {12, 21, 1}, "low": {23, 32, 2}, "high": {34, 43, 3} }
My approach is as follows:
json jCandles = { {"open", json::array()}, {"high", json::array()}, {"low", json::array()} }; for (unsigned int i = 0; i != jObj["candles"].size(); ++i) { jCandles["open"] += jObj["candles"][1]["open"]; }
i get following error:
terminate called after throwing an instance of 'std::domain_error' what(): cannot use operator[] with number
and with jCandles["open"].push_back(jObj["candles"][1]["open"]);
it says cannot use push_back() with number
I do not know how to handle the error. Can someone help me?