我可以使用以下代码解析简单的 JSON 字符串
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
URL.toString() );
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
finalResult.setText("Done") ;
Result = reader.readLine();
} else {
Result = "error";
}
} catch (ClientProtocolException e) {
Result = "error";
e.printStackTrace();
} catch (IOException e) {
Result = "error";
e.printStackTrace();
}
但现在我有以下 JSON 字符串
[{"Name":"Ali" ,"Age":35,"Address":"cccccccccccc"} ,{"Name":"Ali1" ,"Age":351,"Address":"cccccccccccc1"} ,
{"Name":"Ali2" ,"Age":352,"Address":"cccccccccccc2"}
]
和阶级代表它
package com.appnetics;
import android.R.string;
public class Encounter {
public string Name;
public string Address;
public int Age;
}
我想遍历这个 JSON 并将其转换为list<Encounter>
任何想法如何做到这一点