连接到ASP.NET API Jsonobject时出错

时间:2018-12-30 08:27:44

标签: java android json

我试图将android studio中的项目连接到Asp.net API,并且我正在使用Volley Lib来获取Json请求,但是当我尝试获取jsonobject时我得到了按摩

这是JSON响应
enter image description here

我收到此消息
enter image description here

这是我的代码

public class MainActivity extends AppCompatActivity {


public static final String GET_BY_ID = ("http://10.10.4.29:8010/api/Feedback/1");

EditText id;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    id = (EditText) findViewById(R.id.idtxt);

}
public void click(View v) {
    if (v.getId() == R.id.btnget) {
        insertData (id.getText().toString()) ;
    }

}
public void  insertData (String value){
    HashMap<String,String> param = new HashMap<String, String>();
    param.put("?id=",value);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, GET_BY_ID,null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            try {

                JSONObject ob = response.getJSONObject("user");
                String name = ob.getString("UserName");
                Toast.makeText(getBaseContext(),name,Toast.LENGTH_LONG).show();
            } catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();

            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getBaseContext(),error.getMessage(),Toast.LENGTH_LONG).show();

        }


    })
    {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            headers.put("User-agent", "My useragent");
            return headers;
        }};

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(request);
}

}

0 个答案:

没有答案