将数据从android推送到xively

时间:2015-03-24 14:13:30

标签: android json xively

我希望能够通过手机读取和写入xively。 它简单的数据交换。即,玩家1向玩家B提供数据A,反之亦然。 我能够从xively中提取数据,但我有点困惑如何在恢复JSONObject(0)等时推送到JSONObject(1)。 现在我正在测试环境中使用:

    public class MainActivity extends Activity {
    TextView thevalue;

    Button getJson;

    private static String url = "https://api.xively.com/v2/feeds/id and key";


    JSONArray user = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getJson = (Button)findViewById(R.id.getdata);
    getJson.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                     new JSONParse().execute();
                    }
            });
}




private class JSONParse extends AsyncTask<String, String, JSONObject> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
         thevalue = (TextView)findViewById(R.id.value);

    }
    @Override
    protected JSONObject doInBackground(String... args) {
            getJson theParser = new getJson();

            JSONObject json = theParser.doIt(url);
            return json;
    }
     @Override
     protected void onPostExecute(JSONObject json) {
             try {

                            user = json.getJSONArray("datastreams");
                            JSONObject c = user.getJSONObject(0);

                            String curval = c.getString("current_value");
            Log.i("JSONARR", user.toString());
                            thevalue.setText(curval);

            } catch (JSONException e) {
                    e.printStackTrace();
            }
     }
}
}

0 个答案:

没有答案