サーバーを立て、サーバー内に[1,2,3,4,5,6,7,8]という配列があります。それをUnityからPost通信で取得すると以下のように返ってきます。
data
1{ 2 "RETURN": [ 3 1, 4 2, 5 3, 6 4, 7 5, 8 6, 9 7, 10 8 11 ] 12}
この状態から[1,2,3,4,5,6,7,8]を取り出し、各要素を個別で取り出せるようにしたいです。
試したコードは以下のコードです。「request.downloadHandler.text」は上のdataです。
C#
1Dictionary<string, object> response = Json.Deserialize(request.downloadHandler.text) as Dictionary<string, object>; 2int a = response["RETURN"][1]; 3Debug.Log(a);
希望する出力は2ですが、以下のようなエラーが出ました。
error CS0021: Cannot apply indexing with [] to an expression of type 'object'
「object型には[]は使えない」と書かれていて「Dictionary<string, object> response = Json.Deserialize(request.downloadHandler.text) as Dictionary<string, object>;」の「<string, object>」の部分を直せばよさそうな気がしますがそれがわかりません。
よろしくお願いいたします。
追記:
使っているライブラリは以下のとおりです。
using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.Networking; using System.Text; using MiniJSON;
回答2件
あなたの回答
tips
プレビュー