1 Reply Latest reply on Nov 19, 2016 10:55 AM by mifo

    WICED 3.7.0 - Bug in JSON parser ?

    romain

      As I'm working with JSON parser, I noticed that everything works fine untile I receive a JSON frame with an object in it (I mean a child object). From the moment I receive such a JSON frame, all objects in the following frames are considered as children (even the root itself). After few investigations, I may have pointed out a bug in the JSON.c file, line 427 :

       

      if ( parent_counter )
      {
          parent_counter-- ;
      
          if ( parent_counter )
          {
              json_object.parent_object = &parent_json_object[ parent_counter - 1 ];
          }
          else
          {
              json_object.parent_object = &parent_json_object[ parent_counter ];
          }
      }
      

       

      In this part of the code, the parser determines the object's parent if it exists (parent_counter != 0) and affects its address to the json_object.parent_object pointer. But the problem is this pointer is never re-initialized (so all objects they will have a parent, even the root of the next JSON frame).

       

      Here is how I solved this issue :

       

      if ( parent_counter )
      {
          parent_counter-- ;
      
          if ( parent_counter )
          {
              json_object.parent_object = &parent_json_object[ parent_counter - 1 ];
          }
          else
          {
              json_object.parent_object = &parent_json_object[ parent_counter ];
          }
      } else {
      
          // NOTE : fix added by Romain
          json_object.parent_object = NULL;
      }
      

       

      I just wanted to expose this so you, so you can confirm this is a bug, and you can take it into consideration for next releases.

       

      Regards