簡體   English   中英

無法在 Android 中將 java 字符串轉換為 JSON 數組

[英]Cannot convert java string to JSON Array in Android

下面是從 MySql 數據庫中獲取數據的查詢,但問題是在瀏覽器中它成功輸出了數據,但在 Android 應用程序中它給出了以下錯誤

Java.Long.String Cannot Convert to JsonArray

if($stem=$con->prepare("select question from MCQs  where c_id=$c_id ")){
$stem->execute ();
$stem->bind_result($question);
$budget=array();
while($stem->fetch())
{
    $temp=array();

    $temp['question']=$question;

    array_push($budget,$temp);
}
echo json_encode($budget);

下面是 JSON 的 Android 端 Java 代碼

                    JSONObject jsonObject = new JSONObject(response);
                    String success = jsonObject.getString("success");
                    JSONArray jsonArray = jsonObject.getJSONArray("data");

                    if (success.equals("1")) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                            String questions = jsonObject1.getString("question").trim();
                            final String opt0ne = jsonObject1.getString("option1").trim();
                            ;
                            String opttwo = jsonObject1.getString("option2").trim();
                            ;
                            String optthree = jsonObject1.getString("option3").trim();
                            final String correctt = jsonObject1.getString("correct").trim();
        JSONObject json = new JSONObject(result);
        JSONArray jArray = json.getJSONArray("data");
        for (int i=0;jArray.length(); i++)
        {
         JSONObject jsonObject1 = jsonArray.getJSONObject(i);

         //try this
         String msg= jsonObject1.getString("success"); 
       }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM