Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wie bekomme ich JSON-Daten aus PHP und zeige sie in Textview in Android an?

Okay, hier ist, was Sie brauchen. Keine Bibliothek von Drittanbietern erforderlich.

try{
    String jsonStr = getFromWeb(); // jsonStr = {"ID":"1","temperature":"33","max_humidity":"33","min_humidity":"34","lowtide":"35","hightide":"35","sunrise":"500","sunset":"530","moonrise":"530","moonset":"540","illumination":"45%"}]
        JSONObject obj = new JSONObject(jsonStr);
        String temperature = obj.getString("temperature");
        TextView tv = (TextView)findViewById(R.id.yourtextviewid);
        tv.setText("Temperature: " + temperature);
    }catch (JSONException e) {
      e.printStackTrace();
    }