This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100SDK: HTTP Client, Jsmn Parser, Failed to initiailze JSON parser

Part Number: CC3100SDK


I have a problem regarding parsing JSON after I made a request to an HTTP server (  It says Failed to initialize JSON parser. When I try to debug it, it the jsmn_parse() function exit with value 0. I expect a JSON payload returned from the server as shown in the picture below (when I tried using POSTMAN). 

This problem does not happen when I using original http_client demo which uses as the server. The JSON is successfully parsed. 

This confused me because both servers returning JSON payload.

I appreciate if someone can help with this. Thank you

Best wishes,


Code involve:

     \brief This function parse JSON data

     \param[in]      ptr - Pointer to JSON data

     \return         0 on success else -ve


 _i32 ParseJSONData(_i8 *ptr)
     _i32            retVal = 0;
     _i32            noOfToken;
     jsmn_parser     parser;
     jsmntok_t       *tokenList;
     _i8             printBuffer[4];

     /* Initialize JSON PArser */

     /* Get number of JSON token in stream as we we dont know how many tokens need to pass */
     noOfToken = jsmn_parse(&parser, (const char *)ptr, strlen((const char *)ptr), NULL, 10);
     if(noOfToken <= 0)
         CLI_Write(" Failed to initialize JSON parser\n\r");
         return -1;


     /* Allocate memory to store token */
     tokenList = (jsmntok_t *) malloc(noOfToken*sizeof(jsmntok_t));
     if(tokenList == NULL)
         CLI_Write(" Failed to allocate memory\n\r");
         return -1;

     /* Initialize JSON Parser again */
     noOfToken = jsmn_parse(&parser, (const char *)ptr, strlen((const char *)ptr), tokenList, noOfToken);
     if(noOfToken < 0)
         CLI_Write(" Failed to parse JSON tokens\n\r");
         retVal = noOfToken;
         CLI_Write(" Successfully parsed ");
        // sprintf((char *)printBuffer, "%ld", noOfToken);
         CLI_Write((_u8 *)printBuffer);
         CLI_Write(" JSON tokens\n\r");


     return retVal;