java - gson with mixed read -
i'm trying read json gson, can't "simple" gson example work.
from: https://sites.google.com/site/gson/streaming
public list<message> readjsonstream(inputstream in) throws ioexception { jsonreader reader = new jsonreader(new inputstreamreader(in, "utf-8")); list<message> messages = new arraylist<message>(); reader.beginarray(); while (reader.hasnext()) { message message = gson.fromjson(reader, message.class); messages.add(message); } reader.endarray(); reader.close(); return messages; }
here's problem, if try with:
jsonreader reader; gson gson = new gson(); gson.fromjson(reader,program.class);
it doesn't build.
the method fromjson(string, class<t>) in type gson not applicable arguments (jsonreader, class<program>)
there seems method according eclipse: fromjson(jsonreader arg0, type arg1)
replace
import android.util.jsonreader;
with
import com.google.gson.stream.jsonreader
did it! =)
Comments
Post a Comment