json - 我很难在检查器中恢复我的变量 id
问题描述
你能帮我在unity的inspector中获取id的值吗?我在统一控制台中有一个 json,我做了一个程序来访问这个 json 中的数据,然后在统一检查器中恢复它。对于“位置”,它是有效的,但对于“id”没有。我尝试了很多方法,但没有奏效。
这是我在启动函数和更新函数中的代码,我已经搜索过,但我没有找到如何为 id 执行此操作:
我正在使用 SimpleJSON。
if(mono != null)
{
JSONNode id = Face["mono"]["id"].AsInt;
JSONNode position = Face["mono"]["position"];
Vector3 pos = new Vector3(position["x"].AsFloat, position["y"].AsFloat, position["z"].AsFloat);
int ident = new ident(id);
x = pos.x;
y = pos.y;
z = pos.z;
id= ident.id;
}
private void Update()
{
Vector3 newPosition = new Vector3(x, y, z);
gameObject.transform.localPosition = newPosition;
}
这是我的 json: { "cmd": "data", "frame_time": "2021-06-10T11:16:54.678596+00:00", "start_time": "2021-06-10T10:35:40.516632+ 00:00", "streams": [ { "name": "usb0.1245.2", "objects": [ { "name": "face", "mono": { "id": "18", "position “:{“x”:“0.073997”,“y”:“-0.024979”,“z”:“0.677220”}},“多”:[{“id”:“18”,“位置”:{“ x": "0.073997", "y": "-0.024979", "z": "0.677220" } } ] } ] } ], "play": {"list": "test", "item": "right_key " } }
解决方案
如果你从你那里得到一个int
,你可以通过设置你的类的一个或一个变量来Face["mono"]["id"].AsInt;
在检查器中设置它,如下所示:public
[SerializeField] private
public myInt = 0; //also [SerializeField] private myInt = 0;
if(mono != null)
{
myInt = Face["mono"]["id"].AsInt;
JSONNode position = Face["mono"]["position"];
Vector3 pos = new Vector3(position["x"].AsFloat, position["y"].AsFloat, position["z"].AsFloat);
int ident = new ident(id);
x = pos.x;
y = pos.y;
z = pos.z;
id= ident.id;
}
private void Update()
{
Vector3 newPosition = new Vector3(x, y, z);
gameObject.transform.localPosition = newPosition;
}
推荐阅读
- python - Python多处理不能正常工作
- apache-pig - 试图找出列中计数最高的行以及 Apache pig 中的计数
- r - 应用程序无法启动。联系作者获取更多信息
- powershell - PowerShell | 将 DIR 添加到 PATH | 在脚本中使用
- reactjs - 删除突变后从服务器重新获取数据
- python - Python 展平深层嵌套 JSON
- django - 为嵌套的 JSON 数据编写正确的循环
- python - Python pandas:如何将多个 groupby 列之一排序为特定/自定义顺序?
- c++ - 从 C++ 中的数字中删除一个数字
- web-scraping - 如何从连续滚动的网站加载信息以使用 beautifulsoup 进行抓取?