Json reader

Discussion to talk about software related topics only.
Post Reply
fredy-gutierrez
Posts: 12
Joined: Fri Dec 11, 2020 8:27 am

Json reader

Post by fredy-gutierrez »

Hi everyone,

I´m working with the json lexer, I was trying to print a post result in json which has a json object in main json object, so I want to print the data of the second json object, I was reading the documentation of json_lexer class and I found this method, FindFullName("obj1.obj2Element") but It return a json_primative_type data so I can´t print it like a string, I tried to print the object using printf("Object [%s] \r\n", JsonInObject.FindFullNameString("obj1.obj2Element")) but It return null, some one know how can I print the result, I will appreciate any help provided

Thanks Fredy

Json example

{
"SUCCESS": true,
"obj1": {
"obj2Element": "value 01",
"obj2Element2": "value 02"
}
}
User avatar
pbreed
Posts: 1081
Joined: Thu Apr 24, 2008 3:58 pm

Re: Json reader

Post by pbreed »

The Lason lexer has member function to do that...
Is this a 2.X or 3.X NNDK (they are very slightly differnt)

Basic outline:
You have a ParsedJsonDataSet pjds;
it has an internal positions...

so

json_primative_type jtype=pjds.FindFullName("obj1.obj2Element");

//Returns the type of object at that location and changes pjds to have the current pointer pointed there...

//So
printf("We found a %s\r\n",GetTypeName(jtype));

switch (jtype)
{
case NOTFOUND: printf ("Not found\r\n"); break;
case STRING: printf("String :%s\r\n",pjds.CurrentString()); break;
case NUMBER: printF("Number %g\r\n", CurrentNumber()); break;

etc....
}

You can call: pdjs.ResetPosition();

To reset the data set to the begning...


Also:
//Print to stdio
void PrintObject(bool pretty=false);

//Print to a char buffer, returns chars written
int PrintObjectToBuffer(char * buffer, int maxlen,bool pretty=false);

//print to an FD
void PrintObjectToFd(int fd,bool pretty=false);
User avatar
pbreed
Posts: 1081
Joined: Thu Apr 24, 2008 3:58 pm

Re: Json reader

Post by pbreed »

If your working in 3.X then then explain more of what your doing and we might have some big short cuts using the config system,,, to reduce your workload..
fredy-gutierrez
Posts: 12
Joined: Fri Dec 11, 2020 8:27 am

Re: Json reader

Post by fredy-gutierrez »

Hi, hanks a lot, I will try to do it, thanks for your answer
User avatar
pbreed
Posts: 1081
Joined: Thu Apr 24, 2008 3:58 pm

Re: Json reader

Post by pbreed »

Let me know if that fixes things for you.
Post Reply