{
"statusCode": "200",
"flag": 0,
"obj": {
"checkFile": {
"id": 1,
"osName": "",
"fileType": "",
"fileName": "",
"downloadUrl":""
},
"resource": {
"id": 2,
"osName": "",
"fileType": "",
"fileName": "",
"downloadUrl":""
},
"xml": {
"id": 3,
"osName": "",
"fileType": "",
"fileName": "",
"downloadUrl":""
}
}
}
unity中如何解析这个Json文件
- 写好对应的类,可以写在同一个c#script中
[System.Serializable]
public class Result<T>
{
public string statusCode;
public int flag;
public T obj;
}
[System.Serializable]
public class ABUrl
{
public int id;
public string osName;
public string fileType;
public string fileName;
public string fileHashcode;
public string fileUrl;
}
[System.Serializable]
public class ABInfo
{
public ABUrl checkFile;
public ABUrl resource;
public ABUrl xml;
}
- 解析Json文件时
Result<ABInfo> result = JsonUtility.FromJson<Result<ABInfo>>("json数据");