2015-10-05 39 views
1

我有以下如何通过从凌空响应变量

ImageView mImageView; 
mTxtDisplay = (TextView) findViewById(R.id.txtDisplay); 
String url = "http://my-json-feed"; 
String xSession = ""; 

JsonObjectRequest jsObjRequest = new JsonObjectRequest 
     (Request.Method.GET, url, null, new Response.Listener<JSONObject>() { 

    @Override 
    public void onResponse(JSONObject response) { 
     /* 


{ 
     "message": "Session created", 
     "session": "d4f7d26799c720eb6b09daa97a1b7e64", 
     "result": { 
     "id": "331339814848696320", 
     "name": "Administrator", 
     "email": "[email protected]", 
     "username": "admin" 
     } 
    } 
      */ 
     xSession = response.getString("session"); 
    } 
}, new Response.ErrorListener() { 

    @Override 
    public void onErrorResponse(VolleyError error) { 
     // TODO Auto-generated method stub 

    } 
}); 

// Access the RequestQueue through your singleton class. 
MySingleton.getInstance(this).addToRequestQueue(jsObjRequest); 

的响应,我可以看到response.getString(“会议”)的价值,但没有填充XSESSION? 为什么xSession没有被填充?请帮忙!

+0

可以显示响应jsonobject? –

+0

您声明了xsession,但为xSession分配了值。 xSession在哪里宣布? – Sharj

+1

对不起,兄弟我在这里输入“xSession”在这个问题上声明xsession,但是在代码中它总是“xSession”。 –

回答

0

尝试在onResponce中记录响应。如果它到达那里,那么请确保xsession的值仅在接收到响应后使用,并且已设置为

+0

添加json响应。 –

1

Java languague区分大小写。你在哪里声明xSession变量?那么,你想要处理的是xsession还是xSession?请查看或发布更多相关的代码。

+0

对不起,我在这里错误地键入“xSession”到xsession这个问题的声明,但在代码中它总是“xSession”。 –

+0

请发布'JSONObject响应'的内容(您可以使用'Log.i(“ABC”,response.toString();'),然后发布logcat信息 – BNK

+0

添加json响应 –