c# josn 数据读取

69 篇文章 1 订阅
public class PlayerReadJosn
{

    public static PlayerProperty ReadJsonData(string name)
    {
        TextAsset JsonText = Resources.Load(name) as TextAsset;
        string jsonstr = JsonText.text;
        //string jsonstr = File.ReadAllText(Application.dataPath + "/"+name+".txt");
        JsonData Jd = JsonMapper.ToObject(jsonstr);
        PlayerProperty pp = new PlayerProperty();
        pp.PlayerPropertys = new List<PlayerPropertyData>();

        for (int i = 0; i < Jd.Count; i++)
        {
            for (int j = 0; j < Jd[i]["playerData"].Count; j++)
            {
                PlayerPropertyData pd = new PlayerPropertyData();
                pd.playerNamer = Jd[i]["playerData"][j]["playername"].ToString();
                pd.playerType = Jd[i]["playerData"][j]["playerType"].ToString();
                pd.playerHeight = Jd[i]["playerData"][j]["playerHeight"].ToString();
                pd.playerGunTarget = Jd[i]["playerData"][j]["playerGunTarget"].ToString();
                pd.playerGun = Jd[i]["playerData"][j]["playergun"].ToString();
                pd.playerBody = Jd[i]["playerData"][j]["playerBody"].ToString();
                pd.playerHead = Jd[i]["playerData"][j]["playerHead"].ToString();
                pd.playerLeftHand = Jd[i]["playerData"][j]["playerLeftHand"].ToString();
                pd.playerRightHand = Jd[i]["playerData"][j]["playerRightHand"].ToString();
                pp.PlayerPropertys.Add(pd);
            }

        }
        return pp;
    }

public class PlayerProperty
{
    public List<PlayerPropertyData> PlayerPropertys;
}

public class PlayerPropertyData
{
    public string playerNamer;
    public string playerType;
    public string playerHeight;
    public string playerGunTarget;
    public string playerGun;
    public string playerHead;
    public string playerBody;
    public string playerLeftHand;
    public string playerRightHand;
}

 /*人物数据 */
{
    "player": {
        "playerData": [
            {
                "playername": "player1",
				"playerType": "Man01",
				"playerHeight":"170",
				"playerGunTarget":"1",
                "playergun": "RD_GUN1",
                "playerBody": "RD_BODY1",
                "playerHead": "RD_HEAD1",
				"playerLeftHand": "RD_HAND_LEFT1",
				"playerRightHand": "RD_HAND_RIGHT1"

            },
            {
                "playername": "player2",
				"playerType": "Man01",
				"playerHeight":"180",
				"playerGunTarget":"1",
                "playergun": "RD_GUN2",
                "playerBody": "RD_BODY2",
                "playerHead": "RD_HEAD2",
				"playerLeftHand": "RD_HAND_LEFT2",
				"playerRightHand": "RD_HAND_RIGHT2"
            }			
        ]
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值