最近我一直试图以JSON的形式从外部源获取一些数据。 我使用的库是Newtonsoft.Json的统一分支。当我在计算机上运行项目时,它从外部源中提取数据,并将其转换为对象。我所创建的UI /文本元素应该显示从我的外部源中提取的数据,当我在我的主计算机上运行项目它没有问题并且数据显示没有问题,但当我将项目发送到我的Hololens,我的调试器获取数据,我可以从字面上看到数据是从外部源提取的,但数据不会出现在hololens上。任何人都可以告诉我如何解决这个问题吗?
我的代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using SimpleJSON;
using Newtonsoft.Json;
[System.Serializable]
public class TimeProperties
{
public string Year { get; set; }
public string Month { get; set; }
public string Day { get; set; }
public string Hour { get; set; }
public string Minutes { get; set; }
public string Seconds { get; set; }
}
[System.Serializable]
public class TimeClass
{
public TimeProperties Time { get; set; }
}
public class test : MonoBehaviour
{
string url = "http://172.16.24.135:8080";
public Text year;
public Text month;
public Text day;
public Text hour;
public Text minutes;
public Text seconds;
private void Start()
{
StartCoroutine(UpdateValues());
}
IEnumerator PullJsonData()
{
Debug.Log("entered");
WWW www = new WWW(url);
yield return www;
if(www.error != null)
{
print("There was an error getting the data: " + www.error);
yield break;
}
string jsonstring = www.text;
var data = JsonConvert.DeserializeObject<TimeClass>(jsonstring);
Debug.Log(data.Time.Seconds);
var jaren = data.Time.Year; //data["Year"].AsInt;
var maanden = data.Time.Month;//data["Month"].AsInt;
var dagen = data.Time.Day;//data["Day"].AsInt;
var uren = data.Time.Hour;//data["Hour"].AsInt;
var minuten = data.Time.Minutes;//data["Minutes"].AsInt;
var seconden = data.Time.Seconds;//data["Seconds"].AsInt;
year.text = "Year: " + jaren;
month.text = "Month: " + maanden;
day.text = "Days: " + dagen;
hour.text = "Hours: " + uren;
minutes.text = "Minutes: " + minuten;
seconds.text = "Seconds: " + seconden;
}
IEnumerator UpdateValues()
{
while (true)
{
StartCoroutine(PullJsonData());
yield return new WaitForSeconds(1);
}
}
}
我通过Visual Studio代码2017使用&#34;发布x86&#34;将它发送到我的hololens。我也收到以下错误:
(Filename: 'C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Display is Transparent
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
There was an error getting the data:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Failed to get spatial stage statics - can't retrieve or interact with boundaries! Error code: '0x80040154'.
(Filename: C:\buildslave\unity\build\Runtime/VR/HoloLens/StageRoot.cpp Line: 20)
entered
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)'
我每秒都从外部源获取JSON数据,因此运行后每秒都会显示在我的调试中: 输入(这是类pulljsondata()中的debug.log)。 获取数据时出错:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
答案 0 :(得分:2)
我设法让一切正常。在我的UI上没有显示任何内容的原因是因为我使用来自github(https://github.com/Microsoft/MixedRealityToolkit-Unity)的MixedRealityToolkit v2017.2.1.2安装了带有Hololens工具包的Unity 2017.3f1。 我是如何设法让它运作的? 我删除了Unity 2017.3f1并安装了Unity 2017.2.1f1并安装了最新版本的MixedRealityToolkit,v2017.2.1.3。 重新安装后,我尝试使用一些元素启动并运行,并正确地从外部URL中提取json数据。