Tuesday, 15 June 2010

php - Android Array with JSON results -


I would like to update a different thread which I have created with some code that I have written which is not working . I am trying to parse my information, after sending the post request, [[user from: "Andrew"], {"user": "Jimmy"}]

I like those users to pick, and add them to the list view. Here is my code for sending HTTP code and then there is my code also to try parsing it and keeping it in the adapter.

  HTTP client httpClient = new DefaultHttpClient (); Http post http post = new html post (htmlUrl); & Lt; NameValuePair & gt; NameValuePair = New ArrayList & lt; NameValuePair & gt; (); NameValuePair.add (New BasicNameValuePair ("user name", "brock")); {Try HttpPost.setEntity (New UrlEncodedFormEntity (nameValuePair)); } Hold (unsupported encoding exception e) {e.printStackTrace (); } Try {HttpResponse response = httpClient.execute (httpPost); // Writing feedback to log logs log ("HTPP response:", response.toString ()); } Catch (ClientProtocolException E) {// log e Write an exception for the exception. } Hold (IOException e) {// log e Write an exception for the exception. } Try {JSONObject Pending User = New JSONObject ("$ myArray"); } Hold (JasonX Express E) {e.printStackTrace (); } // Read the reply to the string {BufferedReader Reader = New BufferedReader (New InputStreamRadder ("UTF-8"), 8); Stringbilder sb = new stringbiller (); String line = null; While ((line = reader. Readline ())! = Null () {sb.append (row + "\ n"); }                 is close(); Result = sb.toString (); } Hold (exception e) {return tap; } // convert to string converter {jsonObject = new JSONObject (results); } Hold (JSOXECTION E) {return tap; } Public Zero getJsonResult (JSONObject Pending Request) {pendingRequests = jsonObject; }  

This is where I try to get it and put it on my list

  HTTPSendPost postSender = new HTTPSendPost (); Post sender.setup (500, 050, "tiest", htmlUrl); PostSender.execute (); JSONObject Pending Request = New JSONObject (); PostSender.getJsonResult (pendingRequests); Try (for {int i = 0; i & lt; pending spaces} length (); i ++) {JSONArray userUrray = pendingRequests.getJSONArray ("fromUser"); Pending vacancies Arrayed (I, from user. String ()); }} Hold (JasonX Express E) {e.printStackTrace (); } Arrayadapter & lt; String & gt; Adapter = new array adapter & lt; String & gt; (This, R. L. activity_french, pending vacancies array); PendingRequestsListView.setAdapter (adapter);  

When I try my app, I do not get any results on the list view, any help would be appreciated. Sorry for repost, but now I have a lot of information and code. Next time I will ask a question without the code that I have tried.

Try to use - it's a creator who accepts a JSON string, Can access. For example:

  myJsonString = "{\" Andrew \ ", \" Jimmy \ "}"; JSONArray array = new JSONArray (myJsonString); (Int i = 0; i & lt; arrays.lampon (); i ++) {log. V ("json", array.optString (i)); // You can also use this Log.v ("json", array.getString (i)); // or this, but you have to force yourself Log.v ("Jason", array.get (i) .toString ()); }  

No comments:

Post a Comment