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

Issue in replace exising object #58

Closed
pokevas opened this issue Oct 6, 2016 · 2 comments
Closed

Issue in replace exising object #58

pokevas opened this issue Oct 6, 2016 · 2 comments

Comments

@pokevas
Copy link

pokevas commented Oct 6, 2016

Hello.
I try to replace exising json object with another, but fail.
I use json_object_set_value. Return 0, but JSON invalid.
Code:

        JSON_Value *root_value = json_parse_string(pcBuffer);
        if (!root_value)
            return 1;

        JSON_Object *root_object = json_value_get_object(root_value);
        if (!root_object)
            return 1;

        JSON_Object *protection = json_object_get_object(root_object, "protection");
        if (!protection)
            return 1;

        status = json_object_set_value(protection, "macs", json_parse_string(pchAddedJSON));
        if (status != 0)
            return 1;

        char* result = json_serialize_to_string(root_value);

pchAddedJSON file content:
http://pastebin.com/W2YnuXsj

Exiting JSON file content (before any operations, valid):
http://pastebin.com/X5tjG9hd

After insert JSON file content (invalid file):
http://pastebin.com/90P251D4

@kgabis
Copy link
Owner

kgabis commented Oct 7, 2016

I wasn't able to reproduce this issue. That's the code I used:

#include <assert.h>
#include "parson.h"

int main()
{
    JSON_Value *file1_value = json_parse_file("1.json"); /* http://pastebin.com/X5tjG9hd */
    assert(file1_value != NULL);

    JSON_Object *root_object = json_value_get_object(file1_value);
    assert(root_object != NULL);

    JSON_Object *protection = json_object_get_object(root_object, "protection");
    assert(protection != NULL);

    JSON_Value *file2_value = json_parse_file("2.json"); /* http://pastebin.com/W2YnuXsj */
    assert(file2_value != NULL);

    JSON_Status status = json_object_set_value(protection, "macs", file2_value); 
    assert(status == JSONSuccess);

    char* result = json_serialize_to_string(file1_value);
    assert(result != NULL);

    puts(result);
}

Could you include full example that shows this issue?

@pokevas
Copy link
Author

pokevas commented Oct 7, 2016

Yeah, it is my error.
I have write function and found error in my code. Sorry for false Issue.
Closed.

@pokevas pokevas closed this as completed Oct 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants