使用Newtonsoft.Json.dll进行Json文件的解析:
示例如下:
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurntableTest : MonoBehaviour
{
public class PropBean
{
//id
public string id { get; set; }
//name
public string name { get; set; }
//icon
public string icon { get; set; }
}
// Start is called before the first frame update
void Start()
{
// string reward = "[{\"id\":\"000000020\",\"name\":\"20钻石\",\"icon\":\"httpdl-mwl.cmcm.com//mwl/product/diamonds/1/000000020.png\"}]";
string reward = "[{\"id\":\"010040006\",\"name\":\"蓝色长裙\",\"icon\":\"httpdl-mwl.cmcm.com/mwl/product/clothes/1/010040006.png\"},{\"id\":\"000000010\",\"name\":\"10钻石\",\"icon\":\"httpdl-mwl.cmcm.com//mwl/product/diamonds/1/000000020.png\"},{\"id\":\"000000010\",\"name\":\"10钻石\",\"icon\":\"httpdl-mwl.cmcm.com//mwl/product/diamonds/1/000000020.png\"},{\"id\":\"020030002\",\"name\":\"粉色公主风地毯\",\"icon\":\"httpdl-mwl.cmcm.com/mwl/product/furnitures/1/020030002_t.png\"},{\"id\":\"000000010\",\"name\":\"10钻石\",\"icon\":\"httpdl-mwl.cmcm.com//mwl/product/diamonds/1/000000020.png\"}]";
List<PropBean> data = JsonConvert.DeserializeObject<List<PropBean>>(reward);
Debug.Log(data.Count);
foreach(var v in data)
{
Debug.Log(v.id);
}
}
}
结果如下: