{ "returnCode": 0, "returnMessage": "调用成功", "data": { "total": 15, "list": [ { "id": null, "doorinfo": null, "cityname": null, "linename": null, "metrono": null, "doorid": 17414, "doorno": "222222222222222", "typename": null, "type": null, "faultname": "开门障碍物检测3次,开门障碍物检测2次", "sourcename": null, "happentime": "2023-05-29 00:00:00.000", "dealstatus": null, "countryid": 3, "areaid": 22, "lineid": 27, "metroid": 279, "carriageid": 1738, "firstchar": "H" }, { "id": null, "doorinfo": null, "cityname": null, "linename": null, "metrono": null, "doorid": 13456, "doorno": "HHHT0101101", "typename": null, "type": null, "faultname": "输出口0短路故障,输出口0工作异常,数据总线通信故障,门未经许可离开关锁到位位置故障", "sourcename": null, "happentime": "2023-05-29 00:00:00.000", "dealstatus": null, "countryid": 3, "areaid": 22, "lineid": 27, "metroid": 279, "carriageid": 1738, "firstchar": "H" }, { "id": null, "doorinfo": null, "cityname": null, "linename": null, "metrono": null, "doorid": 13608, "doorno": "HHHT0104101", "typename": null, "type": null, "faultname": "SRAM校验异常", "sourcename": null, "happentime": "2023-05-27 20:44:37.000", "dealstatus": null, "countryid": 3, "areaid": 22, "lineid": 27, "metroid": 282, "carriageid": 1756, "firstchar": "H" }, { "id": null, "doorinfo": null, "cityname": null, "linename": null, "metrono": null, "doorid": 13738, "doorno": "HHHT0102503", "typename": null, "type": null, "faultname": "开门障碍物检测2次", "sourcename": null, "happentime": "2023-05-27 16:51:31.000", "dealstatus": null, "countryid": 3, "areaid": 22, "lineid": 27, "metroid": 280, "carriageid": 1748, "firstchar": "H" }, { "id": null, "doorinfo": null, "cityname": null, "linename": null, "metrono": null, "doorid": 13560, "doorno": "HHHT0103101", "typename": null, "type": null, "faultname": "关门时间过长", "sourcename": null, "happentime": "2023-05-27 14:46:56.000", "dealstatus": null, "countryid": 3, "areaid": 22, "lineid": 27, "metroid": 281, "carriageid": 1750, "firstchar": "H" } ], "pageNum": 1, "pageSize": 5, "size": 19, "startRow": 0, "endRow": 18, "pages": 1, "prePage": 0, "nextPage": 0, "isFirstPage": true, "isLastPage": true, "hasPreviousPage": false, "hasNextPage": false, "navigatePages": 8, "navigatepageNums": [ 1, 2, 3 ], "navigateFirstPage": 1, "navigateLastPage": 1 } }返回结果是这些,请求方式为post,unity webgl获得的数据显示在文本框中代码怎么写
时间: 2023-07-06 10:43:11 浏览: 123
REQ Modeler:需求建模工具-开源
使用Unity的UnityWebRequest和LitJson库可以很方便地解析JSON数据。以下是示例代码,其中`url`是POST请求的URL地址,`postData`是POST请求的数据。
```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.Collections.Generic;
using LitJson;
public class Example : MonoBehaviour
{
public UnityEngine.UI.Text resultText;
void Start()
{
StartCoroutine(PostRequest());
}
IEnumerator PostRequest()
{
string url = "your_post_url_here";
string postData = "your_post_data_here";
// Send POST request
UnityWebRequest request = new UnityWebRequest(url, "POST");
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
// Parse response
if (request.result == UnityWebRequest.Result.Success)
{
string json = request.downloadHandler.text;
JsonData data = JsonMapper.ToObject(json);
string result = "Return Code: " + data["returnCode"] + "\n";
result += "Return Message: " + data["returnMessage"] + "\n";
result += "Data: " + data["data"] + "\n";
resultText.text = result;
}
else
{
Debug.Log(request.error);
}
}
}
```
注意:在使用LitJson库解析JSON数据之前,需要先将JSON字符串转换为JsonData对象。示例代码中使用的是`JsonMapper.ToObject()`方法。
阅读全文