iT邦幫忙

0

錯誤訊息Value Query of type java.lang.String cannot be converted to JSONArray

  • 分享至 

  • xImage

拜託各位幫我解決這個錯誤: 我因該已經轉型態了會甚麼還會有錯誤
https://ithelp.ithome.com.tw/upload/images/20190110/20109685p1Dc75h2kQ.png

package com.example.wells.ndr_text;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class DBphp {
    private static HttpClient hC;
    private static HttpPost hP;
    public static String DBstring(String i,String Wcook,String url){
        String result="錯誤";
        try{
            hC=new DefaultHttpClient();
            hP=new HttpPost(url+"/index.php");
            hP.addHeader("Cookie",Wcook+";expires=thu,31-Dec-37 23:55:22 GHT; path=/");

            ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("S1",i));
            hP.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

            HttpResponse hR=hC.execute(hP);
            HttpEntity hE=hR.getEntity();
            InputStream inputStream=hE.getContent();
            BufferedReader bufReader=new BufferedReader(new InputStreamReader(inputStream,HTTP.UTF_8),8);
            StringBuilder builder =new StringBuilder();
            String line=null;
            while((line = bufReader.readLine())!=null){
                builder.append(line+"\n");
            }
            inputStream.close();
            result=builder.toString();


        }catch (Exception e){
            result=e.toString();
        }finally {
            hC.getConnectionManager().shutdown();
        }

        return result;
    }
}

php

index
<?php
require_once("SQL_data.php");
$insertSQL=isset($_POST["S1"])<>NULL?$_POST["S1"]:"select * from user";
mysql_select_db($database,$GD);
$Result=mysql_query($insertSQL,$GD) or die(mysql_error());

while($r = mysql_fetch_assoc($Result))
	$output[]=$r;
	
print(json_encode($output,JSON_UNESCAPED_UNICODE)); //中文不轉成unicode碼
mysql_close();
?>
SQL_data
<?php
$hostname="------";
$username="------";
$password="-------";
$database="-------";
$GD=mysql_pconnect($hostname,$username,$password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES UTF8");
mysql_query("SET CHARACTER_SET_CLTENT='utf8'");
mysql_query("SET CHARACTER_SET_RESULTS='utf8'");
?>
看更多先前的討論...收起先前的討論...
請問您後來有解決嗎
我也有同樣的問題
我後來檢查是我網頁有錯誤 你可以考慮先在網頁的欄位 放值 是否正常
已經成功了 太感謝你啦
a95364226 iT邦新手 5 級 ‧ 2022-04-28 00:14:31 檢舉
可以請問您最後是修改哪裡的程式碼嗎?謝謝~因為我也使跟著youtube做卡在這QQ
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答