Hi everyone,
I'm hitting a wall on this one. I'm trying to parse a JSON file and
the code never sees the 3rd debugging line:
Log.v("Sachin","1 ************************* Before reading
file");
InputStream is =
mContext.getResources().openRawResource(R.raw.recipe_database);
// InputStream is =
Recipe.class.getResourceAsStream( "recipe_database.txt");
String jsonTxt = IOUtils.toString( is );
jsonTxt.trim();
Log.v("Sachin","2 THIS OUTPUTS FINE*** " + jsonTxt);
JSONObject the_json = (JSONObject)
JSONSerializer.toJSON( jsonTxt ); // The culprit
Log.v("Sachin","3 CODE DOESN'T REACH HERE
************************* Before reading file");
Here is what my data looks like (and it shows correctly in the second
Log message (tagged this output is fine):
{"recipes":
[{
"image":"example",
"ingredients":"Ingredients: 1",
"instructions":"Instructions: 1"
},
{
"image":"example",
"ingredients":"Ingredients: 2",
"instructions":"Instructions: 2"
},
{
"image":"example",
"ingredients":"Ingredients: 3",
"instructions":"Instructions: 3"
},
{
"image":"example",
"ingredients":"Ingredients: 4",
"instructions":"Instructions: 4"
},
{
"image":"example",
"ingredients":"Ingredients: 5",
"instructions":"Instructions: 5"
},
{
"image":"example",
"ingredients":"Ingredients: 6",
"instructions":"Instructions: 6"
},
{
"image":"example",
"ingredients":"Ingredients: 7",
"instructions":"Instructions: 7"
}
]}
Here is the exception I see:
09-20 02:42:34.669: WARN/dalvikvm(1202): Unable to resolve superclass
of Lnet/sf/json/JSONException; (567)
09-20 02:42:34.699: WARN/dalvikvm(1202): Link of class 'Lnet/sf/json/
JSONException;' failed
09-20 02:42:34.699: WARN/dalvikvm(1202): VFY: unable to resolve
exception class 380 (Lnet/sf/json/JSONException;)
09-20 02:42:34.699: WARN/dalvikvm(1202): VFY: unable to find exception
handler at addr 0x2e
09-20 02:42:34.699: WARN/dalvikvm(1202): VFY: rejected Lnet/sf/json/
JSONSerializer;.toJSON (Ljava/lang/Object;Lnet/sf/json/
JsonConfig;)Lnet/sf/json/JSON;
09-20 02:42:34.713: WARN/dalvikvm(1202): VFY: rejecting opcode 0x0d
at 0x002e
09-20 02:42:34.713: WARN/dalvikvm(1202): VFY: rejected Lnet/sf/json/
JSONSerializer;.toJSON (Ljava/lang/Object;Lnet/sf/json/
JsonConfig;)Lnet/sf/json/JSON;
09-20 02:42:34.719: WARN/dalvikvm(1202): Verifier rejected class Lnet/
sf/json/JSONSerializer;
09-20 02:42:34.739: WARN/dalvikvm(1202): threadid=25: thread exiting
with uncaught exception (group=0x4000fe70)
Any ideas? Any alternative, less error-prone ways to parse a JSON file
in Java?
Thanks!
Sachin.-
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en