- Home /
How to parse Json file in android?
Thanks to any response.
I've met some problem with parse the Json file of Facebook's Graph API in Unity, the codes can run well in the platform of PC but of Android, it met with some error code as " Type 'Object' doesn't support slicing", the codes below is what I used to parse the Json file of Facebook
=====================
import System.Globalization;
var url :String =""; private var encoding: System.Text.UnicodeEncoding;
function Start () { // Start a download of the given URL var www : WWW = new WWW (url);
// Wait for download to complete
yield www;
var t1: String=convertEscString(www.text);
var hh: Hashtable = eval(t1);
for (var i: int=0; i<hh["data"].length; i++)
{
Debug.Log("name="+hh["data"][i]["name"]+" id="+hh["data"][i]["id"]);
}
}
====================
the problem seems like Unity with Android platform cannot work with the Object of Hashtable?
Really really wanna some help to make Unity android work with JSON well, thanks to any response and help.
Answer by rabbitfang · Jan 12, 2012 at 05:28 AM
I believe your issue is with the line var hh: Hashtable = eval(t1);
. The eval()
function takes a string, parses the code contained within, executes the code, and then returns the result. The result that is returned has an unknown type at compile time. As the Android and iOS platforms require that all data types be known at compile time, the eval()
function is not supported on iOS or Android (reference).
You will need to code your own parser for JSON, or use one that already exists (see MiniJSON).
Answer by fuzzyduckling · Aug 23, 2012 at 08:20 PM
Did anyone figure this out? searched everywhere... this is the closest
Your answer
Follow this Question
Related Questions
How to refer to internal json file on Android? 1 Answer
Unity Facebook integration for android 0 Answers
Turning off SSO on Facebook's Unity SDK for Android 0 Answers
Android + Facebook SDK 0 Answers