json으로는 다음과 같습니다안드로이드에서 JSon 데이터를 어떻게 얻을 수 있습니까?
[{"id":"1","name":"Mihai","email":"[email protected]","password":"1234","phone":"765889345"},{"id":"2","name":"Robin","email":"[email protected]","password":"1234","phone":"765453434"}]
// Json
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDialog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
.penaltyLog()
.build());
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
TextView uid = (TextView) findViewById(R.id.titlu_anunt1);
TextView name1 = (TextView) findViewById(R.id.descriere_anunt1);
TextView email1 = (TextView) findViewById(R.id.telefon_anunt1);
JSONObject json = null;
String str = "";
HttpResponse response;
HttpClient myClient = new DefaultHttpClient();
HttpPost myConnection = new HttpPost("http://appz.esy.es/get_user.php");
try {
response = myClient.execute(myConnection);
str = EntityUtils.toString(response.getEntity(), "UTF-8");
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
try {
JSONArray jArray = new JSONArray(str);
json = jArray.getJSONObject(0);
uid.setText(json.getString("id"));
name1.setText(json.getString("name"));
email1.setText(json.getString("email"));
}
catch (JSONException e) {
e.printStackTrace();
}
가 어떻게 내 textviews에 모든 개체를 추가 할 수있는 코드? 지금은 첫 번째 텍스트 뷰에서 json의 객체 하나만 표시 할 수 있지만 ID를 증가시키고 싶습니다. id1 정보를 표시하고 싶습니다. 이름, 위치 및 기타 내용을 textviews에 표시하고 싶습니다. 1. 그 후에 id2에 이름과 위치를 textviews에 표시하고 싶습니다. 2.
문제는 무엇 :
방금이를 추가 할 필요가 요청을 만들려면? 너는 json을 가져올 수 없다? 너는 json을 파싱 할 수 없다? 또는 구문 분석 된 json을 사용하여 앱의 뷰를 업데이트 할 수 없습니까? –'json = sb.toString();'. 승인. 이제 json은 언급 한 json 텍스트를 포함해야합니다. 지금까지는 괜찮습니까? – greenapps
이러한 요청에 대해 Android Volley를 사용해보십시오. JSONObjectRequest가 있습니다. – Robert