Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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
无法将thingspeak json传递给android_Android_Json - Fatal编程技术网

无法将thingspeak json传递给android

无法将thingspeak json传递给android,android,json,Android,Json,我读取了bmp180的传感器读数,并将其传递给thingspeak,然后显示了图形。现在我想将thingspeak的json发送到我的android手机。但是thingspeak数据中的json没有发送到我的手机中。如果有任何帮助,我们将不胜感激。以下是我的代码: public class MainActivity extends Activity { private static final String PATIENTS_LIST_URL = "http://thingspeak.com/

我读取了bmp180的传感器读数,并将其传递给thingspeak,然后显示了图形。现在我想将thingspeak的json发送到我的android手机。但是thingspeak数据中的json没有发送到我的手机中。如果有任何帮助,我们将不胜感激。以下是我的代码:

public class MainActivity extends Activity {

private static final String PATIENTS_LIST_URL = "http://thingspeak.com/channels/201342/field/1.json";

ArrayList<HashMap<String, String>> patientList;

 Button button;
    TextView textview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textview=(TextView) findViewById(R.id.textView);
        button = (Button) findViewById(R.id.button_get_string);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GetJsonData();
            }
        });

    }

private void GetJsonData() {
    final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
            PATIENTS_LIST_URL, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
         //  Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
           textview.setText(response.toString());

            try {

                JSONArray  data = response.getJSONArray("feeds");

            JSONObject eachData = data.getJSONObject(0);
            String  address=eachData.getString("field2");

             //   Toast.makeText(getApplicationContext(),
                     //   "field1::"+address, Toast.LENGTH_SHORT).show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    // Snack(error.getMessage());
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String>map = new HashMap<String,String>();
            return map;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(jsonObjReq);
}
}
公共类MainActivity扩展活动{
私有静态最终字符串PATIENTS\u LIST\u URL=”http://thingspeak.com/channels/201342/field/1.json";
ArrayList患者列表;
按钮;
文本视图文本视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview=(textview)findViewById(R.id.textview);
按钮=(按钮)findViewById(R.id.button\u get\u字符串);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
GetJsonData();
}
});
}
私有void GetJsonData(){
final JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.POST,
患者列表URL,空,新响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
//Toast.makeText(MainActivity.this,response.toString(),Toast.LENGTH_SHORT.show();
setText(response.toString());
试一试{
JSONArray data=response.getJSONArray(“提要”);
JSONObject eachData=data.getJSONObject(0);
字符串地址=eachData.getString(“字段2”);
//Toast.makeText(getApplicationContext(),
//字段1::“+地址,Toast.LENGTH_SHORT).show();
}捕获(JSONException e){
e、 printStackTrace();
}
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
错误。printStackTrace();
//零食(error.getMessage());
}
}
) {
@凌驾
受保护的映射getParams()引发AuthFailureError{
Mapmap=新的HashMap();
返回图;
}
};
RequestQueue RequestQueue=Volley.newRequestQueue(this);
add(jsonObjReq);
}
}

字段2
不存在于Json响应的提要部分

试着改变

String address=eachData.getString(“field2”)

String address=eachData.getString(“field1”)

从URL中截短的响应以供参考:

{
   "channel":{
      "id":201342,
      "name":"Weather Monitoring Station",
      "description":"The channel provides live weather information of the city such as temperature and atmospheric pressure.",
      "latitude":"0.0",
      "longitude":"0.0",
      "field1":"Temperature",
      "field2":"Pressure",
      "created_at":"2016-12-09T08:32:45Z",
      "updated_at":"2017-02-10T15:46:27Z",
      "last_entry_id":371
   },
   "feeds":[
      {
         "created_at":"2017-01-26T07:33:03Z",
         "entry_id":272,
         "field1":"29.57"
      },
      {
         "created_at":"2017-01-26T07:33:25Z",
         "entry_id":273,
         "field1":"29.61"
      }
      ....
   ]
}

field2
不存在于Json响应的提要部分

试着改变

String address=eachData.getString(“field2”)

String address=eachData.getString(“field1”)

从URL中截短的响应以供参考:

{
   "channel":{
      "id":201342,
      "name":"Weather Monitoring Station",
      "description":"The channel provides live weather information of the city such as temperature and atmospheric pressure.",
      "latitude":"0.0",
      "longitude":"0.0",
      "field1":"Temperature",
      "field2":"Pressure",
      "created_at":"2016-12-09T08:32:45Z",
      "updated_at":"2017-02-10T15:46:27Z",
      "last_entry_id":371
   },
   "feeds":[
      {
         "created_at":"2017-01-26T07:33:03Z",
         "entry_id":272,
         "field1":"29.57"
      },
      {
         "created_at":"2017-01-26T07:33:25Z",
         "entry_id":273,
         "field1":"29.61"
      }
      ....
   ]
}

添加您对问题的回答。添加您对问题的回答。