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

Cannot parse more than one object #506

Closed
itsHaseebSaeed opened this issue Oct 18, 2019 · 2 comments
Closed

Cannot parse more than one object #506

itsHaseebSaeed opened this issue Oct 18, 2019 · 2 comments

Comments

@itsHaseebSaeed
Copy link

I have tried everything to split json objects so that json_tokener_parse() could parse it.

My Code: json_tokener_parse() doesn't work if there are more than 1 object in the json file but works good when it have one object. I have read all the documentation but couldn't find a way to divid string objects and parse each object at a time.

[{
    "hash":"121234365869689789789fghgh",
    "time":"1999999",
    "TxIn":["121312313","21312312","23123123"]
},
{
    "hash":"221234365869689789789fghgh",
    "time":"2999999",
    "TxIn":["2121312313","21312312","23123123"]
},
{
    "hash":"321234365869689789789fghgh",
    "time":"3999999",
    "TxIn":["3121312313","21312312","23123123"]
}]
@hawicz
Copy link
Member

hawicz commented Oct 18, 2019

Your example here has a single object. If that's actually what your input looks like, then it is correct that you only get a single object back.
On the other hand, if you have another object (immediately) after that one, simply grab the char_offset of where the previous call to json_tokener_parse_ex left off, and call it again starting from that point in your buffer.
e.g. starting from the example in the docs at http://json-c.github.io/json-c/json-c-0.13/doc/html/json__tokener_8h.html#a61679f178111963a9ffa3c8179553f7a, you might do something like:

mystring += tok->char_offset;
jobj = json_tokener_parse_ex(tok, mystring, strlen(mystring));

assuming you have all your bytes already available in memory.

@hawicz
Copy link
Member

hawicz commented Oct 21, 2019

Closing, since no additional detail was provided.

@hawicz hawicz closed this as completed Oct 21, 2019
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