Json的编写
[
{
"name": "1",
"a": 80,
"b": 35,
"c": 55,
"d": 72,
"e": 31
},
{
"name": "2",
"a": 58,
"b": 69,
"c": 47,
"d": 49,
"e": 51
},
{
"name": "3",
"a": 49,
"b": 42,
"c": 64,
"d": 52,
"e": 38
},
{
"name": "4",
"a": 59,
"b": 39,
"c": 40,
"d": 68,
"e": 77
}
]
json的数据类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Data
{
public string name;
public float a;
public float b;
public float c;
public float d;
public float e;
public Data(string name, float a, float b, float c, float d, float e)
{
this.name = name;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
}
}
json的解析
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
public class LunZhuanTu : MonoBehaviour
{
List<Data> datas = new List<Data>();
// Start is called before the first frame update
void Start()
{
datas = JsonConvert.DeserializeObject<List<Data>>(Resources.Load<TextAsset>("data").text);
}
}