-2

我想从数据库中获取结果作为数组。我有一张“commande”桌子,里面有存货。我想以数组的形式获取库存。像这样的东西:array[0],array[],array[2] 这是我的表命令的结构(idfichecmd idproduit idclt qte datecmd)

这是我的代码:

String response = null;
String res = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("",));   
try {
    Log.i("","<<<<<<<<<<<<<<<<<<<<TRY");      
    response = CustomHttpClient.executeHttpPost("http://0.0.0.0/GetCmdDetails.php",nameValuePairs); 
    res=response.toString();
    // res = res.trim();
    //res= res.replaceAll("\\s+","");
    //error.setText(res);

} catch (Exception e) {
    Log.i("","<<<<<<<<<<<<<<<<<<<<Catch");
}

//parse json data
try{
    JSONArray jArray = new JSONArray(res);
    //-----------------------------------------
    //nom= new String[jArray.length()];
    //prenom= new String[jArray.length()];
    //----------------------------------------
    for (int i=0;i<jArray.length();i++) {
        JSONObject json_data = jArray.getJSONObject(i)
4

1 回答 1

0

首先,测试您的查询是否给出了正确的结果。

我使用这个解决方案来获取 jsonarray:

使用 HttpClient 调用 web 服务。

private List<NameValuePair> parameters;

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(//yoururl);
    int statusCode = -1;
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(this.parameters));
        HttpResponse response = httpClient.execute(httpPost);
        statusCode = response.getStatusLine().getStatusCode();

 //Get your inputstream here and convert it to json after

    BufferedReader in = new BufferedReader
                        (new InputStreamReader(response.getEntity().getContent()));
于 2012-06-04T10:54:21.987 回答