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!
Answer by Sarah Zhang · Aug 24, 2020 at 08:30 AM
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; }