1

I am new to json and need to send some data from server to client. I receive data in client as a json string but need to convert it to ArrayList<NameValuePair>. I have tried:

Type type = new TypeToken<ArrayList<NameValuePair>>() {}.getType();
ArrayList<NameValuePair> arrayList = new Gson().fromJson(response, type);

But I it throws exception, so I need a better method to do it. I hope my situation is clear. All valid answers will be appreciated.

3
  • 09-12 11:31:20.992: W/System.err(2985): java.lang.RuntimeException: Unable to invoke no-args constructor for interface org.apache.http.NameValuePair. Register an InstanceCreator with Gson for this type may fix this problem. Commented Sep 12, 2012 at 6:01
  • please post an example of your json string. Commented Sep 12, 2012 at 6:30
  • i got another method,m requiremnt is over thanks,anyways Commented Sep 14, 2012 at 4:57

1 Answer 1

3

I think the below code is helpful for you.

Type type = new TypeToken<ArrayList<BasicNameValuePair>>() {}.getType();
Sign up to request clarification or add additional context in comments.

1 Comment

Ah. Thanks. Never thought BasicNameValuePair would be the answer to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.