所以我有一个看起来像这样的json文件:
{
"timeStamp": 1768,
"unix": 1546922595852,
"events": [
{ "id": 9, "channel": 1, "activity": 0.997, "azimuth": 159.318, "elevation": 41.631 }
]
}
{
"timeStamp": 1776,
"unix": 1546922595863,
"events": [
{ "id": 9, "channel": 1, "activity": 1.000, "azimuth": 159.343, "elevation": 41.612 },
{ "id": 26, "channel": 2, "activity": 0.998, "azimuth": 290.540, "elevation": 23.337 }
]
}
我希望能够根据时间戳号或Unix时间调用数组中的不同信息(例如“方位角”和“海拔”值)。我该怎么办?我正在使用Jsoncpp,到目前为止我有这个。
#include <iostream>
#include <fstream>
#include <jsoncpp/json/json.h>
using namespace std;
int main() {
ifstream ifs("tracked.json");
Json::Reader reader;
Json::Value obj;
reader.parse(ifs, obj); // Reader can also read strings
cout << "Azimuth: " << obj["1768"]["events"]["azimuth"].asString() << end$
cout << "Elevation: " << obj["1768"]["events"]["elevation"].asString() <<$
return 1;
}