我有以下 json
{
"android_play_store_link": "xyz",
"ios_app_store_link": "",
"sticker_packs": [
{
"identifier": "1",
"name": "abc",
"publisher": "Jane Doe",
"tray_image_file": "xyz.png",
"image_data_version":"1",
"avoid_cache":false,
"publisher_email":"",
"publisher_website": "",
"privacy_policy_website": "",
"license_agreement_website": "",
"stickers": [
{
"image_file": "abc.webp",
"emojis": ["☕","🙂"]
},
{
"image_file": "cdf.webp",
"emojis": ["😩","😰"]
},
{
"image_file": "efg.webp",
"emojis": ["☕","🙂"]
}
]
}
]
}
到目前为止我还不熟悉 json,我该如何反序列化它?
我知道如何从统一的持久数据路径中执行基本的读写代码。但我该如何处理这个 json 呢?
我的主要目标是当玩家赢得关卡时,新的键和值将添加到“贴纸”属性中,此外,在一些关卡之后,我想稍后添加对贴纸包属性的更改。
另外,我将如何修改特定贴纸包项目中图像数据版本的值?
提前致谢
最佳答案
您可以使用Newtonsoft.Json库进行反序列化和序列化。在下面找到相应的 C# 类。
public class Sticker
{
public string image_file { get; set; }
public IList<string> emojis { get; set; }
}
public class StickerPack
{
public string identifier { get; set; }
public string name { get; set; }
public string publisher { get; set; }
public string tray_image_file { get; set; }
public string image_data_version { get; set; }
public bool avoid_cache { get; set; }
public string publisher_email { get; set; }
public string publisher_website { get; set; }
public string privacy_policy_website { get; set; }
public string license_agreement_website { get; set; }
public IList<Sticker> stickers { get; set; }
}
public class Root
{
public string android_play_store_link { get; set; }
public string ios_app_store_link { get; set; }
public IList<StickerPack> sticker_packs { get; set; }
}
反序列化代码:
Root root = JsonConvert.DeserializeObject<Root>(json);
关于c# - Unity如何序列化和反序列化复杂的嵌套json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62134059/