I'm new to RapidJson, and I need to build an app using it.
For now what I have is a JSon string that I get from the Yahoo API Weather, it looks like this :
{
query: {
count: 1,
created: "2015-10-21T20:40:02Z",
lang: "fr-FR",
results: {
channel: {
item: {
condition: {
code: "27",
date: "Wed, 21 Oct 2015 9:59 pm CEST",
temp: "59",
text: "Mostly Cloudy"
}
}
}
}
}
}
And my function that habdle the data is here :
void MyCurl::dataHandle(const std::string &data)
{
// std::cout << data << std::endl;
Document d;
d.Parse(data.c_str());
std::cout << d["temp"].GetString() << std::endl;
}
The last line throw :
rapidjson/document.h :866 : rapidjson::GenericValue<Encoding, Allocator>&
rapidjson::GenericValue<Encoding, Allocator>::operator[](const
rapidjson::GenericValue<Encoding, SourceAllocator>&) [with SourceAllocator =
rapidjson::MemoryPoolAllocator<>; Encoding = rapidjson::UTF8<>; Allocator =
rapidjson::MemoryPoolAllocator<>]: assertion <false> failed.
How can I access to the temperature and the text ?
Thanks for your help !
The format of the JSon is a bit special and I only had to dig throw all the array.
So now my line looks like :
std::cout << d["query"]["results"]["channel"]["item"]["condition"]["text"].GetString() << std::endl;