我的网址是 .php 格式:主机名/文件名/topstory.php
在解析时,我收到以下错误......
11-28 09:47:57.603: E/class com.example.jsonexample.AndroidJSONActivity(749): Failed to download file
11-28 09:47:57.603: W/System.err(749): org.json.JSONException: End of input at character 0 of
11-28 09:47:57.638: W/System.err(749): at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
11-28 09:47:57.638: W/System.err(749): at org.json.JSONTokener.nextValue(JSONTokener.java:93)
11-28 09:47:57.654: W/System.err(749): at org.json.JSONArray.<init>(JSONArray.java:87)
11-28 09:47:57.654: W/System.err(749): at org.json.JSONArray.<init>(JSONArray.java:103)
11-28 09:47:57.667: W/System.err(749): at com.example.jsonexample.AndroidJSONActivity.onCreate(AndroidJSONActivity.java:34)
11-28 09:47:57.673: W/System.err(749): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-28 09:47:57.683: W/System.err(749): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-28 09:47:57.683: W/System.err(749): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 09:47:57.683: W/System.err(749): at android.os.Looper.loop(Looper.java:123)
11-28 09:47:57.698: W/System.err(749): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-28 09:47:57.698: W/System.err(749): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 09:47:57.698: W/System.err(749): at java.lang.reflect.Method.invoke(Method.java:521)
11-28 09:47:57.698: W/System.err(749): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-28 09:47:57.698: W/System.err(749): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-28 09:47:57.698: W/System.err(749):
这是我的代码:
public class AndroidJSONActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(getApplicationContext(),"sdasdsadsa231",2100).show();
String readTwitterFeed = readTwitterFeed();
try {
JSONArray jsonArray = new JSONArray(readTwitterFeed);
Log.i(AndroidJSONActivity.class.getName(),
"Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(AndroidJSONActivity.class.getName(), jsonObject.getString("text"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private String readTwitterFeed() {
Toast.makeText(getApplicationContext(),"sdasdsadsa231",3100).show();
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("....../video.php");
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
Toast.makeText(getApplicationContext(),"sdasdsadsa",4000).show();
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(AndroidJSONActivity.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"sdasdsa323424326a",4000).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"sdasdsa323424326a",4000).show();
e.printStackTrace();
}
return builder.toString();
}
}
我的档案...
{"view":"topstory","content":[{"story_id":"128","title":"testuser2","story_description":"
testuser2<\/p>","story_video_file":"","story_video_link":"","images":..
请观察文件,它在数据之间有一个行间距(之后
故事描述“:”),
那个空间有什么问题吗..请建议我解决这个问题....