2017-03-02 26 views
0

我試圖得到一些servlet的變量,都通過Ajax調用傳遞。但我越來越構造JSONobject(字符串)是未定義的錯誤。我也導入了所需的lib。請幫助構造函數的JSONObject(字符串)是未定義的錯誤 - 沒能解決

import com.google.gson.Gson; 
 
import com.google.gson.JsonArray; 
 
import com.google.gson.JsonElement; 
 
import com.google.gson.reflect.TypeToken; 
 

 
import org.json.simple.JSONArray; 
 
import org.json.simple.JSONObject; 
 
import org.json.simple.parser.JSONParser; 
 
import org.json.simple.parser.ParseException; 
 
import org.json.*; 
 

 

 
public class insertserv extends HttpServlet { 
 
\t private static final long serialVersionUID = 1L; 
 
\t 
 
\t 
 
\t protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
 
\t {  
 
\t \t 
 
\t \t System.out.println("I am inside insert"); 
 
\t  String json = ""; 
 
\t \t 
 
\t \t 
 
\t \t BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); 
 
\t  
 

 
\t    if (br != null) { 
 
\t     json = br.readLine(); 
 
\t    } 
 
\t 
 
\t System.out.println(json); 
 
\t  
 
\t JSONObject wholedata= new JSONObject(json); 
 
\t \t 
 
\t \t \t \t 
 
\t response.setContentType("application/json"); 
 
\t \t PrintWriter out= response.getWriter(); 
 
\t \t 
 
\t } 
 
}

+0

當你打印json時,你看到了什麼? –

+0

我得到的數據,我從ajax調用「data:JSON.stringify({」test「:masterdata}),」我正在獲取所需的數據。但在下一行我得到構造函數錯誤 – Jsel

+0

這看起來像Java,所以我添加了這樣的標籤。如果我錯了,請糾正它。 –

回答

1

去除org.json.simple.JSONObject;並用org.json.JSONObject更新;它解決了我的問題

相關問題