p
ackage com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import bb.mobrep.R;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class JSONActivity extends Activity {
public String readJSONFeed(String URL) {
StringBuilder stringBuilder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(URL);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
Log.w("str", line.toString());
stringBuilder.append(line);
}
} else {
Log.e("JSON", "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
private class ReadJSONFeedTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
return readJSONFeed(urls[0]);
}
protected void onPostExecute(String result) {
try {
JSONArray jsonArray = new JSONArray(result);
Log.i("JSON", "Number of surveys in feed: " + jsonArray.length());
Toast.makeText(getBaseContext(), jsonArray.toString(), Toast.LENGTH_SHORT).show();
// ---print out the content of the json feed---
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
// Toast.makeText(getBaseContext(),
// jsonObject.getString("text") +
// " - " + jsonObject.getString("created_at"),
// Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jjson);
new ReadJSONFeedTask().execute("http://220.247.247.130/b.txt");
}
}
完全な文字列を取得できません。"C00000047",""nam で終わります。誰か助けてください。この http://220.247.247.130/c.txt
ファイルは正常に動作します。長い JSON ファイルをダウンロードして表示するにはどうすればよいですか
JSON:
{
"customers": [
{
"id": "C0000002",
"nam": "Asian Pharmacy",
"add": "125 Main Street Kattankudy "
},
{
"id": "C0000003",
"nam": "Asiri Pharmaceuticals",
"add": "213 Galahitiyawa Ganemulla aa"
},
{
"id": "C0000004",
"nam": "Badulla Apothecaries",
"add": "229 Lower Street Badulla. "
},
{
"id": "C0000005",
"nam": "B-Line Pharma",
"add": "Carmel Estate Ibbagamuwa "
},
{
"id": "C0000006",
"nam": "A.K.I. ABEYRATHNA",
"add": "47/K/18 SRI WICKRAMA MW SAMMANTHRANA PURA COLOMBO-15"
},
{
"id": "C0000007",
"nam": "Chamee Chemist",
"add": "41275 Magalegoda Veyangoda. "
},
{
"id": "C0000008",
"nam": "Chamee Pharmaceuticals (Pvt) Ltd",
"add": "561/28 New Bus Stand Anuradhapura "
},
{
"id": "C0000009",
"nam": "Chandrasiri Chemists",
"add": "279B Morris Road Maitipe Galle."
},
{
"id": "C0000010",
"nam": "CHL Pharmaceuticals",
"add": "41 E Railway Avenue Nugegoda. "
},
{
"id": "C0000011",
"nam": "City Medicals",
"add": "487 Hospital Road Jaffna "
},
{
"id": "C0000012",
"nam": "City Medicals",
"add": "433 Dockyard Road Trincomalee. "
},
{
"id": "C0000013",
"nam": "Crystal Drugs",
"add": "3 Donald Janz Road Bataganwila Galle."
},
{
"id": "C0000014",
"nam": "Crystal Pharmaceuticals",
"add": "362/1 Dangedara Galle. "
},
{
"id": "C0000015",
"nam": "Damith Distributors",
"add": "275/5 1st Lane Mandawila Road Kesbewa Piliyandala."
},
{
"id": "C0000016",
"nam": "Galle Drug Stores",
"add": "14 Ambagamuwa Road Gampola "
},
{
"id": "C0000017",
"nam": "Gamage Distributors",
"add": "217/C Jaya Mawatha Kadawatha. "
},
{
"id": "C0000018",
"nam": "H.G. Pharmaceuticals",
"add": "24 1st Cross Street Talbet Town Galle."
},
{
"id": "C0000019",
"nam": "Ishini Pharmaceuticals",
"add": "104/6A Templers Road Mt. Lavinia. "
},
{
"id": "C0000020",
"nam": "Kandy Medicals",
"add": "41282 Market Road Mawanella. "
},
{
"id": "C0000021",
"nam": "Kurunegala Medicals",
"add": "4 Weavers Shopping Complex Mihindu Mawatha Kurunegala."
},
{
"id": "C0000022",
"nam": "Lloyed Pharmacy",
"add": "1A Anagarika Dharmapala Mawatha Medagoda Matara."
},
{
"id": "C0000023",
"nam": "M.D.J. Distributors",
"add": "21 St. Joseph's Road Nugegoda. "
},
{
"id": "C0000024",
"nam": "Medicare Enterprises",
"add": "394/6 Biyagama Road Gonawala Kelaniya."
},
{
"id": "C0000025",
"nam": "Mowlana Pharmacy",
"add": "52 Main Street Kalmunai. "
},
{
"id": "C0000026",
"nam": "Nanda Pharmacy",
"add": "2 Fort Road Chilaw. "
},
{
"id": "C0000027",
"nam": "Neelan Pharmaceuticals (Pvt) Ltd",
"add": "Jaffna Road Kilinochchi"
},
{
"id": "C0000028",
"nam": "New Eleans Marketing",
"add": "110 Town Mosque Road Akkaraipattu. "
},
{
"id": "C0000029",
"nam": "New Lanka Pharmacy",
"add": "280 Galle Road Aluthgama. "
},
{
"id": "C0000030",
"nam": "Noor Pharmaceuticals Pvt Ltd",
"add": "50 Main Street Kalmunai. "
},
{
"id": "C0000031",
"nam": "Pharmaco (Pvt) Ltd",
"add": "77 Main Street Negombo "
},
{
"id": "C0000032",
"nam": "Raaj Medicals Stores",
"add": "91 Kandy Road Vavuniya. "
},
{
"id": "C0000033",
"nam": "Ragama Pharmacy",
"add": "34 Tewatte Road Ragama. "
},
{
"id": "C0000034",
"nam": "Ransika Distributors",
"add": "151/11 Tewatta Road Ragama "
},
{
"id": "C0000035",
"nam": "SAS Pharmaceuticals",
"add": "Pahala Ranawana Dewalegama. "
},
{
"id": "C0000036",
"nam": "Sathsara Enterprises",
"add": "495 Mihindu Mawatha Pitipana North Homagama."
},
{
"id": "C0000037",
"nam": "Sigma Impex",
"add": "933 Maradana Road Colombo 08. "
},
{
"id": "C0000038",
"nam": "Southern Pharmaceuticals (Pvt) Ltd",
"add": "1605/32 Crystal Terrace Malabe Road Kottawa Pannipitiya"
},
{
"id": "C0000039",
"nam": "Sri Lanka Pharmacy (Pvt) Ltd",
"add": "39 D S Senanayake Veediya Kandy. "
},
{
"id": "C0000040",
"nam": "Supreme Pharmaceutical Care Distributors",
"add": "30/81 Ramya Gardens Kalapaluwawa Rajagiriya."
},
{
"id": "C0000041",
"nam": "T.C. Distributors",
"add": "315 Galle Road Mt. Lavinia. "
},
{
"id": "C0000042",
"nam": "The New Pharmacy",
"add": "85A Kandy Road Kurunegala. "
},
{
"id": "C0000043",
"nam": "Thusitha Distributors & Pharmacy",
"add": "64 Central Street Hingurakgoda "
},
{
"id": "C0000044",
"nam": "United Pharma (Pvt) Ltd",
"add": "18 Havelock Place Galle. "
},
{
"id": "C0000045",
"nam": "United Pharmacy",
"add": "429/A Pita Kotte Kotte. "
},
{
"id": "C0000046",
"nam": "Viththy Med Engineering",
"add": "22 A St. Anthanys Road Batticaloa. "
},
{
"id": "C0000047",
"nam": "Wettasinghe Pharmaceuticals",
"add": "86 Uyana Road Moratuwa. "
},
{
"id": "C0000048",
"nam": "Wickramasooriya Enterprises",
"add": "Carmel Estate Bakmeegolla Ibbagamuwa "
},
{
"id": "C0000049",
"nam": "Wijemanne Grocers",
"add": "43 Main Street Horana. "
},
{
"id": "C0000078",
"nam": "1a",
"add": "2b 3c 4d 5e"
},
{
"id": "C0000079",
"nam": "dd",
"add": "dd dd dd "
},
{
"id": "C0000080",
"nam": "saliya",
"add": "add1 add 2 add 3 add 4 "
},
{
"id": "C0000081",
"nam": "wasim mirza",
"add": "a11 a22 a33 a44"
},
{
"id": "C0000082",
"nam": "tharindu",
"add": " "
}
]
}