I'm working on a 3d application for Microsoft Hololens using Unity for rendering. I get Json data from a web service and a local file for some settings. Testing the program doesn't give me any errors and actually works quite fine, but when I try to deploy a version on either an emulator or a real hololens I get the following error.
Exception thrown: 'Newtonsoft.Json.JsonReaderException' in Newtonsoft.Json.dll
JsonReaderException: Error reading JToken from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
at Assets.Scripts.CreateHyrarchy.Start()
at Assets.Scripts.CreateHyrarchy.$Invoke0(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: <Unknown> Line: 0)
I think it has something to do with the following lines of code.
string data = reader.ReadData(Globals.Globals.RESOURCEFILE);
JToken jObject = JToken.Parse(data);
Globals gives me my resource path.
public static String RESOURCEFILE = Application.dataPath+"/Resources/pipeLayout.json";
And finaly the json file I would like to read looks like this.
{
"layers":[
{
"type": "water",
"size-multiplier": 2,
"color": "#00f",
"hidden": false
},
{
"type": "gas",
"size-multiplier": 1,
"color": "yellow",
"hidden": false
},
{
"type": "riool",
"size-multiplier": 5,
"color": "#FF0000",
"hidden": false
}
]
}
I'm having the same problem when I call a service, which also return a json string.
they both use a reader object like this.
public String ReadData(String source){
{
//Open a call to a webservice
using (WWW webClient = new WWW(source))
{
//Wait until call is completed
while (!webClient.isDone)
{
new WaitForSeconds(1f);
}
//Get the desired data out
String json = webClient.text.ToString();
return json;
}
}
I try to convert that json data as follows
JObject jObject = JObject.Parse(json);
//Open features array in the object
foreach(JObject pipe in jObject["features"].ToArray())
{
//Parse JSON Object to Creator
PipeLineCreator p = pipe.ToObject<PipeLineCreator>();
}
and Json data looks like this
{
"type": "FeatureCollection",
"totalFeatures": 12,
"features": [
{
"type": "Feature",
"id": "pijpleidingen.3",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[
4.4361,
51.1465
],
[
4.4356,
51.1481
]
]
]
},
"geometry_name": "geom",
"properties": {
"type": "gas",
"diepte_cm": 100,
"bbox": [
4.4356,
51.1465,
4.4361,
51.1481
]
}
},
{
"type": "Feature",
"id": "pijpleidingen.8",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[
4.4362,
51.1474
],
[
4.436,
51.1477
],
[
4.4361,
51.1477
]
]
]
},
"geometry_name": "geom",
"properties": {
"type": "gas",
"diepte_cm": 100,
"bbox": [
4.436,
51.1474,
4.4362,
51.1477
]
}
}
}
Can someone explain me what is happening?