SimpleJSON 返回 null

问题描述

我在 C# 中出现 NullReferenceException 错误:未将对象引用设置为对象的实例 SimpleJSON.JSONNode.Parse (System.String aJSON)(在 Assets/Scenes/scripts/SimpleJSON.cs:553)

我在下面的链接中找到了这篇文章,但我不明白解决方案 SimpleJSON returns null when handling a call from Postmen

谁能帮我解释一下吗?

错误是: NullReferenceException:未将对象引用设置为对象的实例 SimpleJSON.JSONNode.Parse (System.String aJSON)(在 Assets/Scenes/scripts/SimpleJSON.cs:553) SimpleJSON.JSON.Parse (System.String aJSON)(在 Assets/Scenes/scripts/SimpleJSON.cs:1363) Control.Update ()(在 Assets/Control.cs:123)

知道我正在使用 websocket 发送 json 数据并且我正在控制台 unity 中接收它。我使用 simpleJSON 脚本反序列化数据。

此处在 JSONNode root = JSON.Parse(last_message); 行中提供错误的地方; :

db.cases.aggregate([
   { $project: { demographics: 1 } },{ $set: { hasGender_1: { $cond: [{ $eq: ['$demographics.gender',null] },1] } } },{ $set: { hasGender_2: { $cond: [{ $eq: ['$demographics.gender',undefined] },{ $set: { hasGender_3: { $cond: [{ $eq: [{ $type: '$demographics.gender' },"string"] },1,0] } } },]);


{ 
    "demographics" : { "gender" : "F" },"hasGender_1" : 1.0,"hasGender_2" : 1.0,"hasGender_3" : 1.0
},{ 
    "demographics" : { },"hasGender_2" : 0.0,"hasGender_3" : 0.0
},{ 
    "hasGender_1" : 1.0,{ 
    "demographics" : { "gender" : null },"hasGender_1" : 0.0,"hasGender_3" : 0.0
}

SImpleJSON 脚本中的错误 wan in line: while (i

private void Update()
    {
        if (ws == null)
        {
            return;
        }
        List<GameObject> object_to_keep = new List<GameObject>(); 
        JSONNode root = JSON.Parse(last_message);        
        JSONNode Face = root["streams"][0]["objects"][0];

        {
            int id = Face["mono"]["id"].AsInt; 
           

            JSONNode position = Face["mono"]["position"];         
            Vector3 pos = new Vector3(position["x"].AsFloat,position["y"].AsFloat,position["z"].AsFloat);
            
            GameObject mono = GetMonoObject();
            WintualFaceController win_controller = mono.GetComponent<WintualFaceController>();
            win_controller.face_id = id;
            if(mono)
            {
                mono.transform.localPosition = pos;
                object_to_keep.Add(mono);
            }
            else
                print("Mono not found");
        }
}

这是我的json:

{ "cmd": "数据","frame_time": "2021-06-30T09:04:16.464836+00:00","开始时间": "2021-06-30T07:51:33.452079+00:00",“流”:[ { "name": "usb-0001:012.0-3",“对象”:[ { "name": "脸",“单核细胞增多症”: { "id": "190",“位置”: { "x": "-0.012259","y": "0.059731",“z”:“0.707695” } },“多”: [ { "id": "190",“位置”: { "x": "-0.012263","y": "0.059753",“z”:“0.707151” } } ] } ] } ] }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...