JSONParse

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

    private void sendJSON() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpClient okHttpClient=new OkHttpClient();
                Request request=new Request.Builder()
                        .url("http://10.39.1.16/1.json").build();
                try {
                    Response response=okHttpClient.newCall(request).execute();
                    String data=response.body().string();
                    parseJSONWithJSONObject(data);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private void parseJSONWithJSONObject(String data) {
        try {
            JSONArray jsonarray=new JSONArray(data);
            for (int i=0;i

你可能感兴趣的:(JSONParse)