SImplyson解析代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;

public class SimpleJson : MonoBehaviour
{
public TextAsset textAss;
public BagData[] infoArr;
void Start()
{
JSONNode tempJson = JSON.Parse(textAss.text);
//通过索引或者名称获取对应片段内容
//int tempInt = tempJson[0][2][0].AsInt;//索引 导入文件信息的Text的信息
//print(tempInt);
int godsArrCou = tempJson["article"].Count;//在文件 信息 gods下
//print(godsArrCou);
infoArr = new BagData[godsArrCou];
for (int i = 0; i < godsArrCou; i++)
{
BagData tempInfo = new BagData();
tempInfo.id = tempJson["article"][i]["ID"].AsInt;
tempInfo.name = tempJson["article"][i]["Name"].Value;
tempInfo.buyValue = tempJson["article"][i]["BuyValue"].AsInt;
tempInfo.sealValue = tempJson["article"][i]["SaleValue"].AsInt;
tempInfo.dis = tempJson["article"][i]["Dis"].Value;
infoArr[i] = tempInfo;
}
}

posted @ 2019-08-29 16:43  北特  阅读(201)  评论(0编辑  收藏  举报