SimpleJSON returns null when handling a call from Postmen

270 Views Asked by At

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

1

There are 1 best solutions below

0
On

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