处理来自 Postmen 的呼叫时 SimpleJSON 返回 null [英] SimpleJSON returns null when handling a call from Postmen

查看:38
本文介绍了处理来自 Postmen 的呼叫时 SimpleJSON 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装到我的 unity SimpleJSON 中,试图反序列化从 REST-HTTP 调用接收到的调用,该调用包含一个 JSON

当 Simplejson 收到数据时,我验证了

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

由于它是一个静态函数,我复制了它并创建了一个返回版本的对象,该版本返回了我能想到的用于调试的所有数据:i, aJSON[i], Token, Token.Length, TokenName,TokenIsQuoted并将该行更改为

string final = "";

...

case ',':如果(报价模式){Token.Append(aJSON[i]);休息;}final = "aJSON[i] "+aJSON[i] +", token "+ Token + ", length "+ Token.Length +", token Name '" + TokenName+"', IsQuoted " + TokenIsQuoted+"-";if (Token.Length > 0 || TokenIsQuoted){尝试{ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted));}捕获(例外 e){最后+=""+e;返回最终;}}

返回的是:

aJSON[i],, token gzip, length 4, token Name '3000accept-encoding', IsQuoted False- System.NullReferenceException: 未将对象引用设置为对象的实例在 SimpleJSON.JSONNode.ParseTester (System.String aJSON) [0x00316] 在 C:\++Projects\SparkBeyond\Unity\Unity Projects\JSONDeserialize\Assets\SimpleJSON-master\SimpleJSON.cs:690

这表明即使它是一个开关(第 605 行)并且情况是 aJSON[i] 是 ',' 似乎出于某种原因,aJSON[i] 碰巧为空.

你们中有人知道为什么会发生这种情况吗?而且,那部分甚至没有,"数字......

我没有更改脚本.我没有添加 SimpleJSONUnity.cs

问题出现在脚本之前,当我得到 HTTP 答案并将其发送到反序列化时,没有先抓取正文.

在调试了整个答案之后,我发布了它.简单的 json 有一个 ctx 变量,一旦达到 { 数字(json 中的第一个,而不是 HTTP 调用中的第一个)就会初始化.

这就是我被抛出空错误的原因

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

解决方案

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

这篇关于处理来自 Postmen 的呼叫时 SimpleJSON 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆