我已经使用 WWW 将列表从 PHP 导入到 Unity。WWW.text 包含以下内容:
[
{
"playerId": "1",
"playerLoc": "Pwoods"
},
{
"playerId": "2",
"playerLoc": "Shelter"
},
{
"playerId": "3",
"playerLoc": "Cemetery"
}
]
努力使用 Boomlagoon.JSON,但只使用了 1 个对象。我发现我需要在这个列表中反序列化它们。我需要的只是从每个JSON对象中获取数据。如何做到这一点C#?
public class player
{
public string playerId { get; set; }
public string playerLoc { get; set; }
public string playerNick { get; set; }
}
仅返回第一个 KeyValuePair。
IDictionary<string, object> players = Json.Deserialize(serviceData) as IDictionary<string, object>;
foreach (KeyValuePair<string, object> kvp in players)
{
Debug.Log(string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value));
}