Start a new topic

Getting cloud metadata information in Unity

Getting cloud metadata information in Unity

Hi, I'm trying to parse the metadata information of my cloud target. I was able to do that but suddenly the app can't parse the metadata, I think there has been changes to metadata storing format. for exmaple if my metadata looks like below : 


 "Id": 158,

 "Z": 1,

 "Y": 0.72412109375,

 "X": 0



I could get the Id with : target.Metadata , but now I can't and it stops the app at that code and right now there are no way to trace where the error or the proper way to do it is.

I'll appreciate if you can help me with this.

It depends on how the metadata were created. There is an issue when creating the metadata via the cloud api. If you create the metadata as a string and not as a json you will retrieve the json string and not the object. I suggest you to implement a type check on the metadata response: in case you retrieve a string, parse it to a json object, otherwise just use the object. Alternatively, you could update your target's metadata by sending the body type application/json to store a json object instead of a string.

Let me know if this works for you,

Thanks very much Christian, from targetmanager it seems the metadata is stored as string. However I'm confused on how to get it as string. For example you can easily convert a string stored as json to json format with this line: 
JSONObject j = new JSONObject(somestring) but in unity it gives you error when using JSONObject j = new JSONObject(target.metadata) because target.metadata is not an string.

I'll appreciate if you can also help me with this.

Thanks and Regards

I'm not sure if I understood you correctly:
Check the type of target.metadata (string/object). In case it's a string, convert it to a json object. In case it's an object it should already be a json.

Hope that helps,
Login or Signup to post a comment