0

I am attempting to add some Book(title, author, year) into my book table in a server using an AsyncTask, but i am getting missing bookobject as JSONfrom the method addBook(from the server). So i made a bookObject like this:

JSONObject jObj = new JSONObject();
jObj.put("title", "JAVA");
jObj.put("author", "me");
jObj.put("year", 2005);

After that, i wanna use(my intention is to send this book Object):

List<NameValuePair> nameValuePairs = new ArrayList<>(1);
nameValuePairs.add(new BasicNameValuePair(jObj));        //Error
new AaaBookAsyncTask(this).execute(new Pair<>(nameValuePairs, httpClient));

The problem is BasicNameValuePaircannot applied to JSONObject, but now how can i send the book Object? - Any help or hints is very appreciated.Thanks, Carl

carl
  • 388
  • 2
  • 19

1 Answers1

0

You could send the JSON as a string and then decode it on your server before storing it in your database.

Bidhan
  • 10,607
  • 3
  • 39
  • 50
  • I tried this. For example `String json = gson.toJson(book)` but i get the same message: `missing bookobject as JSON`. Therfor i'm thinking simply to send the `Object`. In addition to that i can't reach the server/method inside it. I get just a messge ok or not! – carl May 10 '15 at 16:42