Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中解析JSONArray_Android_Json - Fatal编程技术网

在Android中解析JSONArray

在Android中解析JSONArray,android,json,Android,Json,我对json解析还不熟悉,而且很忙。我必须分析以下内容:- [ { "firstname": abc, "lastname": xyp, "designation" : executive, "user": { "username": "xypabc", "userid": 4003, }, }, { "firstname": pqr, "lastname": vbn, "designati

我对json解析还不熟悉,而且很忙。我必须分析以下内容:-

[
  {
    "firstname": abc,
    "lastname": xyp,
    "designation" : executive,
    "user": {
      "username": "xypabc",
      "userid": 4003,
      },
  },

  {
    "firstname": pqr,
    "lastname": vbn,
    "designation" : security,
    "user": {
      "username": "vbnpqr",
      "userid": 11231,
      },
  },    


  {
    "firstname": ghk,
    "lastname": lkj,
    "designation" : manager,
    "user": {
      "username": "lkjghk",
      "userid": 774,
      },
  }
]
我需要从上面获取“login”和“userid”。下面是我写的代码:-

try {
    JSONArray jsonObj = new JSONArray(response);
    for(int i=0 ; i<jsonObj.length(); i++)
    {                                       
        JSONObject json_Data = jsonObj.getJSONObject(i);
        String userName = json_Data.getString("username");
        String userId = json_Data.getString("userid");
        Log.d("Factors","UserName :- "+userName+" ID :- "+userId);
    }
    }catch (JSONException e) {
        Log.d("Failure","Dude I have failed");
    }.
试试看{
JSONArray jsonObj=新JSONArray(响应);
对于(int i=0;i解析:“用户”

试试看{
JSONArray jsonObj=新JSONArray(响应);
对于(int i=0;i解析:“用户”

试试看{
JSONArray jsonObj=新JSONArray(响应);
对于(int i=0;i解析:“用户”

试试看{
JSONArray jsonObj=新JSONArray(响应);
对于(int i=0;i解析:“用户”

试试看{
JSONArray jsonObj=新JSONArray(响应);

对于(int i=0;i
username
userid
user
JSONObject中)解析用户JSONObject,然后获取用户名和userid的字符串

这样做可以获取
用户名
用户ID

for(int i=0 ; i<jsonObj.length(); i++)
    {                                       
        JSONObject json_Data = jsonObj.getJSONObject(i);
        String userName = json_Data.getJSONObject("user").getString("username");
        String userId = json_Data.getJSONObject("user").getString("userid");
        Log.d("Factors","UserName :- "+userName+" ID :- "+userId);
    }

for(int i=0;i
username
userid
user
JSONObject中解析用户JSONObject,然后获取用户名和userid的字符串

这样做可以获取
用户名
用户ID

for(int i=0 ; i<jsonObj.length(); i++)
    {                                       
        JSONObject json_Data = jsonObj.getJSONObject(i);
        String userName = json_Data.getJSONObject("user").getString("username");
        String userId = json_Data.getJSONObject("user").getString("userid");
        Log.d("Factors","UserName :- "+userName+" ID :- "+userId);
    }

for(int i=0;i
username
userid
user
JSONObject中解析用户JSONObject,然后获取用户名和userid的字符串

这样做可以获取
用户名
用户ID

for(int i=0 ; i<jsonObj.length(); i++)
    {                                       
        JSONObject json_Data = jsonObj.getJSONObject(i);
        String userName = json_Data.getJSONObject("user").getString("username");
        String userId = json_Data.getJSONObject("user").getString("userid");
        Log.d("Factors","UserName :- "+userName+" ID :- "+userId);
    }

for(int i=0;i
username
userid
user
JSONObject中解析用户JSONObject,然后获取用户名和userid的字符串

这样做可以获取
用户名
用户ID

for(int i=0 ; i<jsonObj.length(); i++)
    {                                       
        JSONObject json_Data = jsonObj.getJSONObject(i);
        String userName = json_Data.getJSONObject("user").getString("username");
        String userId = json_Data.getJSONObject("user").getString("userid");
        Log.d("Factors","UserName :- "+userName+" ID :- "+userId);
    }
for(inti=0;i
JSONArray jresult=newjsonarray(响应);
jresult=json.getJSONArray(“用户”);
for(int i=0;i
JSONArray jresult=新的JSONArray(响应);
jresult=json.getJSONArray(“用户”);
for(int i=0;i
JSONArray jresult=新的JSONArray(响应);
jresult=json.getJSONArray(“用户”);
for(int i=0;i
JSONArray jresult=新的JSONArray(响应);
jresult=json.getJSONArray(“用户”);
for(int i=0;i
如果(结果!=null)
{
尝试
{
JSONObject jobj=result.getJSONObject(“结果”);
字符串状态=jobj.getString(“状态”);
if(status.equals(“true”))
{
JSONArray数组=jobj.getJSONArray(“用户”);
对于(int x=0;x
如果(结果!=null)
{
尝试
{
JSONObject jobj=result.getJSONObject(“结果”);
字符串状态=jobj.getString(“状态”);
if(status.equals(“true”))
{
JSONArray数组=jobj.getJSONArray(“用户”);
对于(int x=0;x
如果(结果!=null)
{
尝试
{
JSONObject jobj=result.getJSONObject(“结果”);
字符串状态=jobj.getString(“状态”);
if(status.equals(“true”))
{
JSONArray数组=jobj.getJSONArray(“用户”);
对于(int x=0;x  JSONArray jsonObj = new JSONArray(response);
                for(int i=0 ; i<jsonObj.length(); i++)
                {                                       
                    JSONObject json_Data = jsonObj.getJSONObject(i);
                    String firstname = json_Data.getString("firstname");
                    String lastname = json_Data.getString("lastname");
                    String designation = json_Data.getString("designation");

                    JSONArray jsons1 = json_Data.getJSONArray("user");
                    for (int j = 0; j < jsons1.length(); j++) {

                        JSONObject jsonss = jsons1.getJSONObject(j);
                         String username = jsonss.getString("username");
                            String userid = jsonss.getString("userid");
                    }

                }
                }catch (JSONException e) {
                    Log.d("Failure","Dude I have failed");
                }