Closed
Description
So I was trying to test out this json parsing library with a sample JSON file I made. After some hiccups and some help from here and the codeblocks forum (I use Code::Blocks), I was able to build the program. However, when it ran, it returned an error/status code 3.
CONSOLE OUTPUT:
terminate called after throwing an instance of 'Json::RuntimeError'
what(): * Line 1, Column 1
Syntax error: value, object or array expected.
Process returned 3 (0x3) execution time : 7.575 s
Press any key to continue.
The sample JSON file has been checked and is in a valid JSON format.
The code used the Json::Value
type only.
Full Code:
#include "json/json.h"
#include <fstream>
#include <iostream>
int main() {
Json::Value sample;
std::ifstream sample_file("sample.json", std::ifstream::binary);
sample_file >> sample;
// cout << people; //This will print the entire json object.
// The following lines will let you access the indexed objects.
std::cout << "Bible version: ";
std::cout << sample["version"]; // bible version
std::cout << "Sample verse content";
std::cout << sample["testaments"][0]["books"][2]["chapters"][1]["verses"][1]["verse"]; //sample bible verse selection from JSON file
std::cout << "Sample footnote content";
std::cout << sample["testaments"][0]["books"][2]["chapters"][1]["footnotes"][1]["reference"];
std::cout << sample["testaments"][0]["books"][2]["chapters"][1]["footnotes"][1]["footnotes"]; //sample bible footnote selection from JSON file
return 0;
}
Please help, or maybe fix it... Thank you.
Metadata
Metadata
Assignees
Labels
No labels