Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

android - How to pass JSON Object to new activity

I have an application that needs to download JSON from URL using AsyncTask and on onPostExecute() pass that JSON Object to next Activity using putExtra method, but I'm constantly getting an error,which reads "putExtra can only be used to pass strings and not Objects"?How to fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do this when passing the param:

intent.putExtra("json", jsonobj.toString());

And in your new activity parse it like so:

JSONObject obj = new JSONObject(getIntent().getStringExtra("json"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...