Hello Folks,
currently I am trying to import a top level array json file…
The issue is: it runs in unity editor w/o any issue but when I execute a Windows Store hololens build I got this error:
InvalidOperationException: Handle is not initialized.
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at UnityEngine.Internal.$MethodUtility.CreateInstanceAndInvokeDefaultConstructor(IntPtr type, UIntPtr argument0, Int64* argument1)
at UnityEngineProxy.InternalCalls.PInvokeCalls.JsonUtility_CUSTOM_FromJson(IntPtr param_0, Int32 param_1, Int64& outExceptionHandle)
at UnityEngineProxy.InternalCalls.JsonUtility_CUSTOM_FromJson(String json, Type type)
at UnityEngine.JsonUtility.FromJson[T](String json)
at Json.JsonHelper.getJsonArray[T](String json)
at Richy.Data.Memory.loadDummyData()
at Richy.Data.Memory…ctor(Boolean loadDummyData)
at Richy.RichyBehavior.Start()
at Richy.RichyBehavior.$Invoke19(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: Line: 0)
The point of error is:
Wrapper wrapper = JsonUtility.FromJson<Wrapper> (newJson);
newJson parameter contains, what it should and as said it runs either in UnityEditor or in a normal Windows build, but for Windows Store it won´t run.
Interestingly when I don´t use a top level array json it works as well.
In particular
public static T loadJsonObject<T>(string jsonFileName) {
//Json Top Level Array Type
string jsonString = JsonHelper.LoadJsonResource (jsonFileName);
T jsonObject = JsonUtility.FromJson<T> (jsonString);
return jsonObject;
}
Additional information:
File content of wishlist.json (path project/assets/resources/json/wishlist.json)
[
{ “name”: “BMW”, “price”: 41000, “desc”: “New BMW.”},
{ “name”: “Haus”, “price”: 750000, “desc”: “House”},
{ “name”: “Hifi anlage”, “price”: 1000, “desc”: “mega Bass.” }
]
I build a json helper to load top-level array json files:
public static T[] getJsonArray<T>(string json)
{
string newJson = "{ \"array\": " + json + "}";
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>> (newJson);
return wrapper.array;
}
[Serializable]
private class Wrapper<T>
{
public T[] array;
}
The wrapper class for wishlist:
using System;
using UnityEngine;
namespace Richy.Data
{
[Serializable]
public class Wishlist
{
public string name;
public float price;
public string desc;
public Wishlist (string name, float price, string desc)
{
this.name = name;
this.price = price;
this.desc = desc;
}
public static Wishlist CreateFromJSON(string jsonString)
{
return JsonUtility.FromJson<Wishlist>(jsonString);
}
override public string ToString() {
return "name: " + this.name + " price: " + this.price + " desc: " + this.desc;
}
}
}
I am not sure what the problem is. My assumption is that it has something to do with different DotNet version used for Windows Store Project.
Hopefully sb. can help.
2995603–223308–JsonHelper.cs (1.22 KB)