0

I've installed into my unity SimpleJSON in attempt to deserialize the received call from REST-HTTP call that hold a JSON

simpleJSON

that's my script

im listening to localhost 3000 and sending from postman

GET  HTTP/1.1
Host: localhost:3000
Accept: application/json
Content-Type: application/json
cache-control: no-cache
Postman-Token: 3a64322b-a33c-4828-8347-11cdc7da70af
{
    "item": "seeds",
    "Answers": "5",
    "richText": "*some text*"
}------WebKitFormBoundary7MA4YWxkTrZu0gW--

when Simplejson received the data, I verified that the raw data has arrived successfully

however, the proccess dumps an error when engaging the token '3000accept-encoding' (3000 is port number) in line 529.

ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));

since its a static function, i duplicated it and created an object returning version which returned all the data i could think of for debugging: i, aJSON[i], Token, Token.Length, TokenName,TokenIsQuoted and changed the line into

string final = "";

...

case ',':

   if (QuoteMode)
   {
      Token.Append(aJSON[i]);
      break;
   }
   final =  "aJSON[i] "+aJSON[i] +", token "+ Token + ", length "+ Token.Length +", token Name '" + TokenName+"', IsQuoted " + TokenIsQuoted+"-";
   if (Token.Length > 0 || TokenIsQuoted)
   {   
      try
      {
         ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));
      }
      catch(Exception e)
      {
         final+="      "+e;
         return final;
      }
   }

what returned was:

aJSON[i] ,, token gzip, length 4, token Name '3000accept-encoding', IsQuoted False-      System.NullReferenceException: Object reference not set to an instance of an object
  at SimpleJSON.JSONNode.ParseTester (System.String aJSON) [0x00316] in C:\++Projects\SparkBeyond\Unity\Unity Projects\JSONDeserialize\Assets\SimpleJSON-master\SimpleJSON.cs:690 

which indicates that even though its a switch (line 605) and the case is aJSON[i] is ',' it seems like for some reason, aJSON[i] happened to be null.

does any of you know why this could have happened? also, there was not even a ',' digit in that part...

I did not change the script. I did not add the SimpleJSONUnity.cs

likuku
  • 358
  • 6
  • 21
  • I have little ambitions to parse all your code and possibly find a mistake ... what I can say already: SimpleJSON is not ment to be parsed character by character of the input string. It rather expects a valid JSON string as input and can return ceratin items like `var N = JSON.Parse(the_JSON_string); var versionString = N["item"].Value;` you should rather focus on turning the string you receive into a valid JSON string than there should be no issues with it. – derHugo Mar 18 '19 at 12:42
  • Hi you are right. in fact, the problem was before the script when i got the HTTP answer and sent it to Deserialization without grabbing the body first. after debugging the whole answer I released that. Simple json has a ctx variable that initializes once reaching a { digit (1st in the json, not 1st in the HTTP call). that's why i was being thrown a null error thanks – likuku Mar 23 '19 at 15:06

1 Answers1

0

the problem was before the script when i got the HTTP answer and sent it to Deserialization without grabbing the body first.

after debugging the whole answer I released that. Simple json has a ctx variable that initializes once reaching a { digit (1st in the json, not 1st in the HTTP call).

that's why I was being thrown a null error

likuku
  • 358
  • 6
  • 21