- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
is there any document or any example related with JSON parsing. The JSON.c file is in the utilities.
Thanks
Solved! Go to Solution.
- Labels:
-
AWS
-
SDK 3.x
-
TCPIP
-
Web Services
- Tags:
- teaser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just noticed your post for help. In response I put in a quick blog to help you understand how to read JSON files and extract tokens using ZentriOS. ZentriOS is designed to simplify many of the tasks in WICED by abstracting many of the functions into simpler APIs.
Take a look at this Beginners guide to ZentriOS : JSON Parser Example
Hope it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
You can modify the UART demo application to see how JSON parsing works.
In the uart.mk:- Paste the following :-
$(NAME)_COMPONENTS := utilities/cJSON
In uart.c include cJSON.h
#include "cJSON.h"
Copy the following function in uart.c
/* Parse text to JSON, then render back to text, and print! */
void doit(char *text)
{
char *out;cJSON *json;
json=cJSON_Parse(text);
if (!json) {printf("Error before: [%s]\n",cJSON_GetErrorPtr());}
else
{
out=cJSON_Print(json);
cJSON_Delete(json);
// printf("%s\n",out);
WPRINT_APP_INFO(("%s",out));
free(out);
}
}
You can now call the doit(); function with JSON as the text from application_start();
Eg: doit(text1);
Hope that helps.
Best Regards,
AB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your kindly reply, but there is something that i do not understand that i could not find a cJSON.h file under utilities folder. I have JSON_parser so they are different or they are the same file? i am using SDK 3.5.2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
cJSON refers to the open source library ...cJSON download | SourceForge.net
Make sure to put cJSON in libraries/utilities and create a new makefile which includes this source cJSON.c
You can then modify the application makefile to include this cJSON as a component. Finally include the cJSON.h in the app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you mkochhal
i have figured how to use JSON parser which is located in utilization folder in the real one which i asked.
i can explain in details for one who doesn't understand
Here is what i have done:
here we have a seperate parser_function depends on our JSON
static wiced_result_t parse_json_status(wiced_json_object_t * json_object )
{
if(json_object->value_length > 0 && json_object->value_length < sizeof(port)-1)
{
memcpy(port, json_object->value, json_object->value_length);
}
}
so in main part of code
wiced_JSON_parser_register_callback(parse_json_status);
then we are calling wiced_JSON_parser( argument )
after this when we call port we can reach the coming data from port variable.
Best wishes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
I just want to know how does the port variable store data? because if I have to do string operations to find type/payload/ etc, parsing JSON achieves nothing?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i do not understant what do you mean so can you explain it more clearly?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what if your JSON object looks like this:
{"messageType":"status",
"serialNumber":"5724119a-d5d5-11e5-ab30-625662870761",
"timeStamp":"2016-03-17T07:49:58.052496Z",
"payload":{
"deviceInfo":{"model":"2","firmwareVersion":"1.0.11.310"},
"deviceStatus":{
"usageStatus":1,
"performance": {
"batteryPercent":100,
"batteryVolt":200,
"batteryAmp":11,
"batteryHealth":80,
"temperature":25,
"humidity":26,
"waterLevel":10,
"oxygen":120,
"co2":1,
"noise":100,
"leakage":36,
"vibration":5,
"pressure":60
}
},
}
what will port contain?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i got it now. I am sorry i forgot to add a line of code segment so here the line
if(strncmp(json_object->object_string, "port", sizeof("port")-1) == 0)
{
// WPRINT_APP_INFO(("lolll\n"));
if(json_object->value_length > 0 && json_object->value_length < sizeof(port)-1)
{
memcpy(port, json_object->value, json_object->value_length);
// req_led_status[json_object->parent_object->value_length] = '\0';
}
}
so port is my variable and i check my json whether there is any port object at the end of tree. if so i take the value of it to my port variable. For your example it is "noise" or anything within the same branch with noise.
i hope it is more clear.
Best wishes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just noticed your post for help. In response I put in a quick blog to help you understand how to read JSON files and extract tokens using ZentriOS. ZentriOS is designed to simplify many of the tasks in WICED by abstracting many of the functions into simpler APIs.
Take a look at this Beginners guide to ZentriOS : JSON Parser Example
Hope it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for all your help it is more clear now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sure - anything we can do to help you turn that product into a reality!