Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What I am doing wrong?!? #1714

Closed
SzykCech4 opened this issue Aug 20, 2019 · 1 comment
Closed

What I am doing wrong?!? #1714

SzykCech4 opened this issue Aug 20, 2019 · 1 comment
Labels
state: needs more info the author of the issue needs to provide more details

Comments

@SzykCech4
Copy link

SzykCech4 commented Aug 20, 2019

Hello
In first place sorry if it is wrong place to ask for support. But I don't find any links to groups nor mainling list nor forum.

I write unit test form my Settings class (Json based). I have generated Json file (by my Settings class) and I want manually check if it contains all data I wrote.
File is like this:

{"Main":{"DoubleVariable":121312.340012,"IntVariable":-13300,"LLVariable":-100000013200,"ListVariable":["Dana1","Dana2","Dana3","Dana4","Dana i więcej!"],"UIntVariable":13300,"ULLVariable":100000013200,"WStringVariable":[68,97,110,101,32,105,32,119,105,281,99,101,106,33,32,105,32,119,105,281,99,101,106,32,100,97,110,121,99,104,33]}}

As you can see I try to save few types I suppose to use with my Settings class. And as you can see this Json looks good. But I must verify this by my code.
My code is:

    std::vector<unsigned char> lData(eki::gLoadRawFile(s.fileName()));
    json lJson;
    auto lArray(lJson.parse(lData.data()));
    for(auto i(lArray.begin()); lResult && (i != lArray.end()); ++i)
    {
        (*i)["Main"]["IntVariable"].get_to(lInt2);
        if(lInt2 != lInt)
        {
            lResult = false;
            break;
        }
    [...]
    }

Problem is in line:

        (*i)["Main"]["IntVariable"].get_to(lInt2);

I explain this line:

(*i) : Dereference object under iterator I use in order to parse Json.
["Main"]["IntVariable"] : Access to the Main object and IntVariable in it.
.get_to(lInt2) : Store value to int lInt2; variable.
But in this line I got exception:
[json.exception.type_error.302] type must be number, but is null

Please explain to me: What I am doing wrong?
Thanks in advance and Best regards.

@pboettch
Copy link
Contributor

If the contents of the file is an object (something between braces { .. }) it cannot be used as an array.

What is the output of *i inside the loop? (std::cerr << *i << "\n";)

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

3 participants