簡體   English   中英

將jsonarray轉換為字符串

[英]Convert jsonarray to string

我想在代碼中將第一個查詢(課程)的值放到其他查詢(mapcategory)中。 第一個查詢中的值不會在第二個查詢中轉換為字符串。

public String query() throws Exception {
        JSONObject inputJsonObj = new JSONObject();
        JSONArray inputArray = new JSONArray();
        String array=null;
        Database db = new Database();
        db.my_Connection();
        List<HashMap> course =  db.Query("select NAME from file where visual_code='1'");
        inputArray = new JSONArray();
        if(course !=null)
            for (int i=0; i<course.size(); i++){
                HashMap data=(HashMap)course.get(i);
                inputJsonObj = new JSONObject();
                inputJsonObj.put("NAME",(String) data.get("NAME"));     
                inputArray.put(inputJsonObj);
            }
        arra=String.valueOf(course);
        List<HashMap> mapCategory =  db.Query("select PATH from c_"+arra+"_item item" +
                " LEFT JOIN cr_"+arra+"_document doc" +
                " ON item.ref = doc.id WHERE visibility = 1 AND tool = 'document'");
        inputArray = new JSONArray();
        if(mapCategory !=null)
            for (int i=0; i<mapCategory.size(); i++){
                HashMap data=(HashMap)mapCategory.get(i);
                inputJsonObj = new JSONObject();
                inputJsonObj.put("PATH",(String) data.get("PATH"));
                inputArray.put(inputJsonObj);
            }
        db.Close_Connection();
        return inputArray.toString();
    }

我調試此代碼並得到一個錯誤

HTTP狀態500-com.sun.jersey.api.container.MappableContainerException:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:SQL語法有錯誤; 在第1行的'{NAME = TUTORIAL} _item_property項目LEFT JOIN crs_ {NAME = TUTORIAL} _d'附近檢查與您的MySQL服務器版本相對應的手冊,以使用正確的語法。

我只想在結果中獲得“ TUTORIAL”的價值。

你的問題在arra=String.valueOf(course); 因為您將哈希表的字符串表示形式保存在字符串中,所以您需要哈希表中的值。

更換

arra=String.valueOf(course);

arra=course.get("NAME");

暫無
暫無

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

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