question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

Catalog's Item Custom Data

Hi, I am trying to use Custom Data of my Items to store some vital information of each item i.e. time, healing factors, etc.

It works fine in storing the information but when I try to get the data it sends me the data as string which I'm unable to serialize into a JSON object even when I store it in the JSON format.

"CustomData": "{\"test\":\"{\\\"test1\\\":\\\"test2\\\"}\"}"

Is there any limitation? Or am I missing something or doing something wrong? Any help would be appreciated, thanks!

apisunity3dsdksCloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

The CustomData of Catalog Items is returned as JSON string. You need to parse it to the JSON Object manually. For example, in CloudScript, you need to parse it using JSON.parse(string) method. You can refer to the following testing function.

handlers.GetItems = function (args, context) {

    var result = server.GetCatalogItems({});
    var itemList = result.Catalog;
    var customData = ParseCustomData(itemList[0].CustomData);
    return  customData;
    
}

function ParseCustomData(CustomData) {
    
    var JSONObject = JSON.parse(CustomData);
    return JSONObject;
}
	
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.