-1

こんにちは、これは Json フォーム リソースをロードする私のコードです。URL から Json をロードするようにこのコードを変更したいのですが、どうすればよいですか? このコードを変更する方法を教えてください。JsonフォームのURLをロードしたいだけです助けてください

private JSONObject getContent() throws IOException, JSONException 
{
    BufferedReader bufferedReader = null;
    try
    {
        InputStream inStream = getResources().openRawResource(R.raw.json);
        BufferedInputStream bufferedStream = new BufferedInputStream(inStream);
        InputStreamReader reader = new InputStreamReader(bufferedStream);
        bufferedReader = new BufferedReader(reader);
        StringBuilder builder = new StringBuilder();
        String line = bufferedReader.readLine();
        while (line != null) 
        {
            builder.append(line);
            line = bufferedReader.readLine();
        }
        return new JSONObject(builder.toString());
    } 
    finally 
    {
        if (bufferedReader != null) 
        {
            bufferedReader.close();
        }
    }
}

/**
 * Populates the table in the main view with data.
 * 
 * @param data
 *            the read JSON data
 * @throws JSONException
 */
private void populateTable(JSONObject data) throws JSONException 
{
    JSONArray dataArray = data.getJSONObject("observations").getJSONArray("data");
    final TableLayout table = (TableLayout) findViewById(R.id.table);
    for (int i = 0; i < dataArray.length(); i++) 
    {
        final View row = createRow(dataArray.getJSONObject(i));
        table.post(new Runnable() 
        {
            public void run() 
            {
                table.addView(row);
             }
        });
    }
}

/**
 * Creates a row for the table based on an observation.
 * 
 * @param item
 *            the JSON object containing the observation
 * @return the created row
 * @throws JSONException
 */

private View createRow(JSONObject item) throws JSONException 
{
    View row = getLayoutInflater().inflate(R.layout.rows, null);
    ((TextView) row.findViewById(R.id.localTime)).setText(item.getString("local_date_time_full"));
    ((TextView) row.findViewById(R.id.apprentTemp)).setText(item.getString("apparent_t"));
    return row;
 }
4

1 に答える 1