0 Replies - 840 Views - Last Post: 11 February 2013 - 07:20 PM Rate Topic: -----

#1 kikib92   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 106
  • Joined: 26-September 11

Parsing File Contents into JSON Object

Posted 11 February 2013 - 07:20 PM

Hello all! I'm working on a project for one of my classes. In order to begin the project, we have to parse the contents of a file into a JSON object. I'm currently stuck just trying to create the JSON object and could use a bit of help. I am using XCode 4.6 and have included the json.c and json.h files in my project (found here: JSON) .

This is my main method:
#include <string>
#include <fstream>
#include <streambuf>
#include <iostream>
#include <cstdlib>

#include "json.h"
using namespace std;

int main () {
    ifstream infile;
    infile.open ("/Users/kbooras/Desktop/Countries.txt");
    if (infile.is_open())
        cout << "good open \n";
        string inputStr((istreambuf_iterator<char>(infile)), istreambuf_iterator<char>());
        json_value data = * json_parse(inputStr.c_str());
        cout << "Error opening file \n";
    return 0;

The program builds successfully but I keep getting this error and I don't know what is going wrong:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)

The error occurs at this line:
json_value data = * json_parse(inputStr.c_str());

And I get the output:
good open

Could someone please help me figure this out? Thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1