I encountered a problem when doing pico development, the parsed json data could not be displayed normally. At first I thought that the text could not be obtained, but after trying various methods, I found that the parsing method was wrong. Go directly to the code ↓
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeviceData : MonoBehaviour
{
private void InitData()
{
//json文本放到streamingAssets文件夹里
StartCoroutine(WWW_Tex(Application.streamingAssetsPath + "/Config.txt"));
}
IEnumerator WWW_Tex(string url)
{
WWW www = new WWW(url);
yield return www;
if (www.isDone && www.error == null)
{
string str = www.text;
//使用unity自带的json解析方式,Newtonsoft.Json在安卓端不支持
Devices ds = JsonUtility.FromJson<Devices>(str);
foreach(DeviceInfo info in ds.devices)
{
deviceDic.Add(info.Name, info.Des);
}
}
}
}