kazuho/picojson

Couldn't parse simply JSON string

bl4ck5un opened this issue · 1 comments

I'm trying to parse a simple JSON string but value.is<picojson::object>() is false. Am I doing anything wrong? What's probably unique is that the outermost JSON is an array.

#include <iostream>
#include <string>
#include "../picojson.h"

using namespace std;

int main()
{

    const char* _json_resp = "[{\"id\": \"bitcoin\",\"name\": \"Bitcoin\",\"symbol\": \"BTC\",\"rank\": \"1\",\"price_usd\": \"1802.22\", \"price_btc\": \"1.0\",\"24h_volume_usd\": \"449860000.0\", \"market_cap_usd\": \"29430703155.0\", \"available_supply\": \"16330250.0\", \"total_supply\": \"16330250.0\", \"percent_change_1h\": \"0.5\", \"percent_change_24h\": \"1.32\", \"percent_change_7d\": \"14.22\", \"last_updated\": \"1494797050\"}]";

    picojson::value value;
    string err_msg = picojson::parse(value, _json_resp);
    if (!err_msg.empty()) {
      printf("can't parse JSON result: %s\n", err_msg.c_str());
    }

    if (!value.is<picojson::object>()) {
      printf("is not object\n"); // <-- errors
    }
}

Never mind. It turns out I misunderstood what counts an object.