Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

For example:

    Json::Reader reader;
    Json::Value val;
    ifstream file("JSON/test.json");
    bool success = reader.parse(file, val, false);
    vector<string> obj = val.getMemberNames();

    for (int i = 0; i < val.size(); i++)
    {
        // switch type of value
        switch (val.get(obj.at(i), "default").type())
        {
            case stringValue:
                cout << "I'm string" << endl;
                ... need to save **membername** and **value**
                break;
            case intValue:
                cout << "I'm int"  << endl;
                ... need to save **membername** and **value**
                break;
            case nullValue:
                cout << "I'm null"  << endl;
                break;
            case arrayValue:
                 ... code to parse an array (with nested sure) ...
                 ... need to save
                break;
            case objectValue:
                ... code to parse an object (with nested sure) ...
                ... need to save 
                break;
        }
    }

Example JSON file (JSON/test.json):

{
    "layout": "fit",
    "xtype": "viewport",
    "height": 200,
    "style": {
                "backgroundColor": "46f0a8"
             },

           "items": 
           [
             {
                "title": "Management Console",
                "padding": "10 10 10 10",
                "bodyPadding": 10,
                "autoScroll": true,
                "items2": [1, 2, 3]
             }
           ]
 }

In array items, we can see another array (nested) called items2.

May experience the following for arrays:

array[Jacob, Joseph] or
array[{name: Jacob, name: Joseph}] or
array[{name: Jacob}, {name: Joseph}]

For objects it's similar. In each field, can of course be many nested objects/arrays. How do I save data in C++ variables?

share|improve this question
    
It is quite unclear to me, what are you really asking for. I see 3 questions. How do I process array data and object data in jsoncpp library? How do I adapt to different data storing conventions? How do I handle general/nested cases? –  luk32 Apr 15 at 11:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.