Hola y de antemano gracias a todos.
Tengo este codigo:
Código Java:
Ver original/**
* Author: Ravi Tamada
* URL: www.androidhive.info
* twitter: http://twitter.com/ravitamada
* */
package com.example.androidhive.library;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
static JSONObject jObj = null;
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl
(String url, List
<NameValuePair
> params
) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
e.printStackTrace();
}
try {
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.e("JSON_getJSONFromUrl", json);
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
System.
out.
println("JsonParser_try3 "+jObj
); } catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
donde obtengo este resultado:
Código LogCat:
Ver original11-25 15:03:49.942: E/JSON_getJSONFromUrl(921): {"tag":"syncronize","success":1,"error":0,"uid":"546ccc4d8846e1.73207896","user":{"name":"Pablo","email":"
[email protected]","created_at":"2014-11-19 10:58:53","updated_at":null}}{"tag":"syncronize","success":1,"error":0,"uid":"546cd113ebddc7.01724635","user":{"name":"a","email":"aa","created_at":"2014-11-19 11:19:15","updated_at":null}}
11-25 15:03:49.962: I/System.out(921): JsonParser_try3 {"uid":"546ccc4d8846e1.73207896","error":0,"user":{"created_at":"2014-11-19 10:58:53","email":"
[email protected]","updated_at":null,"name":"Pablo"},"success":1,"tag":"syncronize"}
11-25 15:03:49.972: I/System.out(921): JSON_GET_ALL_USER1 {"uid":"546ccc4d8846e1.73207896","error":0,"user":{"created_at":"2014-11-19 10:58:53","email":"
[email protected]","updated_at":null,"name":"Pablo"},"success":1,"tag":"syncronize"}
Como puede ver en el momento que ejecuto: "Log.e("JSON_getJSONFromUrl", json);"`tengo todos los valores, pero al momento de ejecutar: "jObj = new JSONObject(json);" y despues imprimo la variable "System.out.println("JsonParser_try3 "+jObj);" ya solo tengo el primero, he buscado y me han dicho que utilice el jsonarray , pero no tengo ni idea de como hacerlo, he buscado algunos ejemplos y todos me dan error
alguien me puede ayudar o darme un ejemplo?
Gracias
PD: Esta misma pregunta la hice en :
http://stackoverflow.com/questions/2...30634_27113754