Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 分析JSON数组时出错,DOCTYPE_Java_Android_Json_Eclipse_Parsing - Fatal编程技术网

Java 分析JSON数组时出错,DOCTYPE

Java 分析JSON数组时出错,DOCTYPE,java,android,json,eclipse,parsing,Java,Android,Json,Eclipse,Parsing,我有一个工作列表视图,它从我的数据库接收JSON。但是当我尝试使用这个链接时:我得到了“错误解析数据org.json.JSONException:Value” JSON输出是干净的,应该可以工作!我的活动 package com.spxc.ssa.streaming; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; i

我有一个工作列表视图,它从我的数据库接收JSON。但是当我尝试使用这个链接时:我得到了“错误解析数据org.json.JSONException:Value” JSON输出是干净的,应该可以工作!我的活动

package com.spxc.ssa.streaming;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.MenuItem;
import com.spxc.ssa.streaming.task.JsonAsync;
import com.spxc.ssa.streaming.task.JsonAsync.JsonListener;

public class ListShowsController extends SherlockListActivity implements
        OnClickListener {

    private ProgressDialog mDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.dblist);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Shows");

        JsonAsync asyncTask = new JsonAsync();
        // Using an anonymous interface to listen for objects when task
        // completes.
        asyncTask.setJsonListener(new JsonListener() {
            @Override
            public void onObjectReturn(JSONObject object) {
                handleJsonObject(object);
            }
        });
        // Show progress loader while accessing network, and start async task.
        mDialog = ProgressDialog.show(this, getSupportActionBar().getTitle(),
                getString(R.string.loading), true);
        asyncTask.execute("");

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
        }
        return false;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    private void handleJsonObject(JSONObject object) {
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        try {

            JSONArray shows = object.getJSONArray("items");

            for (int i = 0; i < shows.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject e = shows.getJSONObject(i);

                map.put("video_id", String.valueOf(i));
                map.put("video_title", "" + e.getString("video_title"));
                //map.put("season", "Season: " + e.getString("season"));
                map.put("video_location", "" + e.getString("video_location"));
                mylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

        ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.dbitems,
                new String[] { "video_title", "video_location" }, new int[] { R.id.item_title,
                        R.id.item_subtitle });

        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                @SuppressWarnings("unchecked")
                HashMap<String, String> o = (HashMap<String, String>) lv
                        .getItemAtPosition(position);

                Intent myIntent = new Intent(ListShowsController.this,
                        ShowsController.class);
                myIntent.putExtra("video_title", o.get("video_title"));
                //myIntent.putExtra("season", o.get("season"));
                myIntent.putExtra("video_location", o.get("video_location"));
                startActivity(myIntent);
            }
        });

        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

}
package com.spxc.ssa.streaming;
导入java.util.ArrayList;
导入java.util.HashMap;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入com.actionbarsherlock.app.SherlockListActivity;
导入com.actionbarsherlock.view.MenuItem;
导入com.spxc.ssa.streaming.task.JsonAsync;
导入com.spxc.ssa.streaming.task.JsonAsync.JsonListener;
公共类ListShowsController扩展SherlockListActivity实现
onclick侦听器{
私人住宅;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//getWindow().setFormat(像素格式.半透明);
setContentView(R.layout.dblist);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(“显示”);
JsonAsync asyncTask=新的JsonAsync();
//在执行任务时使用匿名接口侦听对象
//完成。
asyncTask.setJsonListener(新的JsonListener(){
@凌驾
公共void onObjectReturn(JSONObject对象){
handleJsonObject(对象);
}
});
//访问网络时显示进度加载程序,并启动异步任务。
mDialog=ProgressDialog.show(这是,getSupportActionBar().getTitle(),
getString(R.string.loading),true);
asyncTask.execute(“”);
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
开关(item.getItemId()){
案例android.R.id.home:
完成();
打破
}
返回false;
}
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
}
私有void handleJsonObject(JSONObject对象){
ArrayList mylist=新的ArrayList();
试一试{
JSONArray shows=object.getJSONArray(“项”);
for(int i=0;i
异步任务

package com.spxc.ssa.streaming.task;

import org.json.JSONObject;

import android.os.AsyncTask;
import android.util.Log;

public class JsonAsync extends AsyncTask<String, Void, JSONObject> {

    public interface JsonListener {
        public void onObjectReturn(JSONObject object);
    }

    public void setJsonListener(JsonListener jsonListener) {
        mListener = jsonListener;
    }

    private JsonListener mListener;
    public static final String TAG = JsonAsync.class.getSimpleName();

    @Override
    protected JSONObject doInBackground(String... params) {
        // The argument passed into tasks are arrays. So you can pass 0 or more
        // arguments, when calling from activity, it's really up to you. They
        // just have to be separated by commas. Like this :
        // new JsonAsync.execute("thisUrl", "thatUrl", "anotherUrl");
        // Although I am only grabbing the first item in the array, by calling
        // params[0] below.

        JSONObject object = null;

        if (params != null && params.length > 0) {
            object = JSONfunctions.getJSONfromURL(params[0]);
        } else {
            Log.e(TAG, "Task needs an argument to be able to retrieve data.");
        }

        // I return the item out of this method, because it is happening of the
        // UI thread, so it can;t update items on the screen. You can work with
        // a database from this method. That is actually recommended.
        return object;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        // This method can touch UI components without throwing an error.
        if (result != null && mListener != null) {
            mListener.onObjectReturn(result);
        }
        super.onPostExecute(result);
    }
}
package com.spxc.ssa.streaming.task;
导入org.json.JSONObject;
导入android.os.AsyncTask;
导入android.util.Log;
公共类JsonAsync扩展异步任务{
公共接口JsonListener{
公共void onObjectReturn(JSONObject object);
}
public void setJsonListener(JsonListener JsonListener){
mListener=jsonListener;
}
私人JsonListener mListener;
公共静态最终字符串标记=JsonAsync.class.getSimpleName();
@凌驾
受保护的JSONObject doInBackground(字符串…参数){
//传递到任务中的参数是数组。因此,您可以传递0或更多
//参数,当从活动中调用时,这实际上取决于您。它们
//只需用逗号分隔即可。如下所示:
//新的JsonAsync.execute(“thisUrl”、“thatUrl”、“anotherUrl”);
//虽然我只是通过调用
//下面的参数[0]。
JSONObject对象=null;
如果(params!=null&¶ms.length>0){
object=JSONfunctions.getJSONfromURL(参数[0]);
}否则{
e(标记“任务需要一个参数才能检索数据”);
}
//我从这个方法中返回这个项,因为它发生在
//UI线程,因此它无法更新屏幕上的项目
//使用此方法创建数据库。这实际上是推荐的。
返回对象;
}
@凌驾
受保护的void onPostExecute(JSONObject结果){
//此方法可以在不引发错误的情况下触摸UI组件。
if(结果!=null&&mListener!=null){
package com.spxc.ssa.streaming;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.MenuItem;
import com.spxc.ssa.streaming.task.JsonAsync;
import com.spxc.ssa.streaming.task.JsonAsync.JsonListener;

public class ListMoviesController extends SherlockListActivity implements
        OnClickListener {

    private ProgressDialog mDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.dblist);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Movies");

        JsonAsync asyncTask = new JsonAsync();
        // Using an anonymous interface to listen for objects when task
        // completes.
        asyncTask.setJsonListener(new JsonListener() {
            @Override
            public void onObjectReturn(JSONObject object) {
                handleJsonObject(object);
            }
        });
        // Show progress loader while accessing network, and start async task.
        mDialog = ProgressDialog.show(this, getSupportActionBar().getTitle(),
                getString(R.string.loading), true);
        asyncTask.execute("http://strongpixel.com/java/movies.php");

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
        }
        return false;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    private void handleJsonObject(JSONObject object) {
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        try {

            JSONArray shows = object.getJSONArray("items");

            for (int i = 0; i < shows.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject e = shows.getJSONObject(i);

                map.put("id", String.valueOf(i));
                map.put("name", "" + e.getString("name"));
                //map.put("date", "Released: " + e.getString("date"));
                map.put("path", "" + e.getString("path"));
                mylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

        ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.dbitems,
                new String[] { "name", "path" }, new int[] { R.id.item_title,
                        R.id.item_subtitle });

        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                @SuppressWarnings("unchecked")
                HashMap<String, String> o = (HashMap<String, String>) lv
                        .getItemAtPosition(position);

                Intent myIntent = new Intent(ListMoviesController.this,
                        MoviesController.class);
                myIntent.putExtra("name", o.get("name"));
                myIntent.putExtra("season", o.get("season"));
                myIntent.putExtra("path", o.get("path"));
                startActivity(myIntent);
            }
        });

        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

}
03-12 08:35:18.722: E/log_tag(25208): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
03-12 09:06:52.877: V/CustomViewAbove(26397): Received ACTION_DOWN
03-12 09:06:52.920: V/CustomViewAbove(26397): onInterceptTouch moved to:(30.26232, 662.0), diff:(29.26232, 1.0), mLastMotionX:1.0
03-12 09:06:52.936: V/CustomViewAbove(26397): onInterceptTouch moved to:(73.95948, 663.08905), diff:(72.95948, 0.08905029), mLastMotionX:1.0
03-12 09:06:52.940: V/CustomViewAbove(26397): this slide allowed true dx: 72.95948
03-12 09:06:52.940: V/CustomViewAbove(26397): Starting drag! from onInterceptTouch
03-12 09:06:52.993: V/SlidingMenu(26397): changing layerType. hardware? true
03-12 09:06:53.229: V/SlidingMenu(26397): changing layerType. hardware? false
03-12 09:06:54.214: V/CustomViewAbove(26397): Received ACTION_DOWN
03-12 09:06:54.450: D/dalvikvm(26397): GC_CONCURRENT freed 73K, 7% free 4495K/4812K, paused 3ms+6ms, total 24ms
03-12 09:06:55.025: E/log_tag(26397): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
JSONfunctions.getJSONfromURL(params[0])
JSONObject object = new JSONObject("<!DOCTYPE html>");