Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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数组用于Asyntask';什么是后台方法?_Java_Android_Json - Fatal编程技术网

Java 如何将两个json数组用于Asyntask';什么是后台方法?

Java 如何将两个json数组用于Asyntask';什么是后台方法?,java,android,json,Java,Android,Json,如何将两个JSONArray用于Asyntask的doInBackground方法 一个JSONArray数据显示在自定义列表视图上,另一个JSONArray数据显示在TextView使用此选项 public class MainActivity extends ActionBarActivity { private ListView mListView; private TextView mTextView; @Override protected void onCreate(Bundle

如何将两个
JSONArray
用于
Asyntask的
doInBackground
方法

一个
JSONArray
数据显示在自定义列表视图上,另一个
JSONArray
数据显示在
TextView

使用此选项

public class MainActivity extends ActionBarActivity {

private ListView mListView;
private TextView mTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mListView = (ListView) findViewById(R.id.listView1);
    mTextView = (TextView) findViewById(R.id.textView1);
}

public void onClick(View v) {
    new NewRequest().execute();
}

public class NewRequest extends AsyncTask<String, Integer, JSONObject> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected JSONObject doInBackground(String... params) {

        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();

            HttpGet httpGet = new HttpGet(
                    "http://firstchoicefood.in/fcfapiphpexpert/phpexpert_order_details.php?order_identifyno=FCF2");

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();

            String response = EntityUtils.toString(httpEntity);

            return new JSONObject(response);

        } catch (Exception e) {
            Log.e("Exception", e.toString());
        }
        return null;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        super.onPostExecute(result);

        try {
            JSONArray OrderDetailItem = result
                    .getJSONArray("OrderDetailItem");

            for (int i = 0; i < OrderDetailItem.length(); i++) {

                JSONObject jsonObject = OrderDetailItem.getJSONObject(i);

                String order_identifyno = jsonObject
                        .getString("order_identifyno");
                String order_type = jsonObject.getString("order_type");
                String status = jsonObject.getString("status");
                String subTotal = jsonObject.getString("subTotal");

                String t = "order_identifyno : " + order_identifyno
                        + "\norder_type : " + order_type + "\nstatus : "
                        + status + "\nsubTotal : " + subTotal;

                mTextView.setText(t);
            }

            JSONArray OrderFoodItem = result.getJSONArray("OrderFoodItem");

            ArrayList<String> alst = new ArrayList<String>();

            for (int i = 0; i < OrderFoodItem.length(); i++) {

                JSONObject jsonObject = OrderFoodItem.getJSONObject(i);

                String RestaurantPizzaItemName = jsonObject
                        .getString("RestaurantPizzaItemName");
                String quantity = jsonObject.getString("quantity");
                String menuprice = jsonObject.getString("menuprice");

                String s = "RestaurantPizzaItemName : "
                        + RestaurantPizzaItemName + "\nquantity : "
                        + quantity + "\nmenuprice : " + menuprice;

                alst.add(s);
            }

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    MainActivity.this, android.R.layout.simple_list_item_1,
                    alst);

            mListView.setAdapter(adapter);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
}
公共类MainActivity扩展了ActionBarActivity{
私有列表视图;
私有文本视图mTextView;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView=(ListView)findViewById(R.id.listView1);
mTextView=(TextView)findViewById(R.id.textView1);
}
公共void onClick(视图v){
新建NewRequest().execute();
}
公共类NewRequest扩展了异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
}
@凌驾
受保护的JSONObject doInBackground(字符串…参数){
试一试{
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpGet HttpGet=新HttpGet(
"http://firstchoicefood.in/fcfapiphpexpert/phpexpert_order_details.php?order_identifyno=FCF2");
HttpResponse HttpResponse=httpClient.execute(httpGet);
HttpEntity HttpEntity=httpResponse.getEntity();
字符串响应=EntityUtils.toString(httpEntity);
返回新的JSONObject(响应);
}捕获(例外e){
Log.e(“异常”,例如toString());
}
返回null;
}
@凌驾
受保护的void onPostExecute(JSONObject结果){
super.onPostExecute(结果);
试一试{
JSONArray OrderDetailItem=结果
.getJSONArray(“OrderDetailItem”);
对于(int i=0;i
这是我使用的XML文件



你尝试了什么,在这里发布。我没有尝试。你能给我发送一些像我的要求一样的样本吗?你从同一个url获得了两个json数组。你能发布web服务url吗?我的要求不同。一个JsonArray数据显示在自定义listview上,另一个TextView让我们在这里就这个问题进行聊天,我无法与你聊天,因为我名声不好…顺便说一句,这是我的电子邮件iddavidjohaan33@gmail.com我们可以继续聊天gmail@David这解决了你的问题吗?感谢它的工作sandeep,但是当我使用自定义列表视图时,我遇到了一个问题,我没有在列表视图上显示数据。