在android中读取简单的json数据

在android中读取简单的json数据,android,json,Android,Json,我试图在android中读取简单的JSON数据,而不使用URL 以下是我的JSON数据。有人能帮我阅读以下数据吗 {"_id":"550ac135a2c513115c6cfa32","UserID":195,"LoginName":"Asdfa","EmailAddress":"adifa1@gmail.com","Password":"Head","Gender":1,"DateOfBirthString":"5-21-1988","DateOfBirth":"1988-05-21T00:00

我试图在android中读取简单的JSON数据,而不使用URL

以下是我的JSON数据。有人能帮我阅读以下数据吗

{"_id":"550ac135a2c513115c6cfa32","UserID":195,"LoginName":"Asdfa","EmailAddress":"adifa1@gmail.com","Password":"Head","Gender":1,"DateOfBirthString":"5-21-1988","DateOfBirth":"1988-05-21T00:00:00","DOB":"21/05/1988","CreatedDate":"2015-03-19T12:29:40.313Z","Status":"P","UserAge":26,"PreffredMaxAge":99,"PreffredMinAge":21,"ProfilePhoto":null,"IsUserOnline":false,"IsUserHomo":false,"ZipCode":"","IsUserSubscribed":false,"ProfileCompletionPoints":-1.0,"LastOnlineTime":null}

创建一个新的JSONObject并将json字符串作为参数传入

    try {
        json_object = new JSONObject(json_str);
    } catch (JSONException) {
        //thrown when it cannot parse the json
      ;
    }

请使用setter gatter为所有属性(ID名称、照片等)为用户创建一个模型类。 我只为id创建

public class AppUser{
private string id,

public void getId(){
return id;
}

public void setId(String id){
this.id = id;
} 
并为AppUser类型创建数组列表

ArrayList<AppUser> userlist = new ArrayList<AppUser>();
有关更多详细信息,请参阅以下教程:


看看这个..很简单

URL myURL=新URL(“您的URL”)

URLConnection tc=myURL.openConnection()

BufferedReader位于//读取行中,使用带有obj“tc”的InputStreamReader

字符串行;
而((line=in.readLine())!=null){
JSONArray ja=新JSONArray(线);
对于(int i=0;i
您尝试了什么?使用json,这会对您有所帮助我已经将整个数据转换成字符串,试图读取它,基于(键、值)对。有人能提供我任何实例吗?您想用这些标记做什么谢谢Yogendra您的回答对我帮助很大
String serverData = "your server response in json";

JSONObject jsonObj = new JSONObject(serverdata);

                        String id= jsonObj .getString("_id");
                        String userID = phone.getString("UserID");
                        ................//parse other attribute 
AppUser user = new AppUser();
user.setId(id);
................// for other attribute 

//save into arraylist

userlist.add(user);
 String line;
while ((line = in.readLine()) != null) {
JSONArray ja = new JSONArray(line);

    for (int i = 0; i < ja.length(); i++) {
    JSONObject jo = (JSONObject) ja.get(i);
    listItems.add(jo.getString("text")); // add in list view
    }