Page 1 of 1

Json reader

Posted: Fri Dec 11, 2020 8:52 am
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"
}
}

Re: Json reader

Posted: Fri Dec 11, 2020 3:17 pm
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);

Re: Json reader

Posted: Fri Dec 11, 2020 3:20 pm
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..

Re: Json reader

Posted: Thu Dec 17, 2020 11:32 am
by fredy-gutierrez
Hi, hanks a lot, I will try to do it, thanks for your answer

Re: Json reader

Posted: Fri Dec 18, 2020 12:09 pm
by pbreed
Let me know if that fixes things for you.