我正在尝试发出一个返回json响应的http get请求.我需要将json响应中的一些值存储在我的会话中.我有这个:
public String getSessionKey(){
BufferedReader rd = null;
StringBuilder sb = null;
String line = null;
try {
URL url = new URL(//url here);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();
while ((line = rd.readLine()) != null)
{
sb.append(line + '\n');
}
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
Run Code Online (Sandbox Code Playgroud)
这将返回字符串中的JSON:
{ "StatusCode": 0, …Run Code Online (Sandbox Code Playgroud) 我有这个EXT JS代码:
Ext.Ajax.request({
url : "xxx",
method : "POST",
params : params,
success : function(response) {
success();
},
failure : function(){
fail();
}
});
Run Code Online (Sandbox Code Playgroud)
url xxx返回这段JSON.
{"success": false }
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这永远不会失败.它永远不会运行该fail()方法success().出了什么问题?
我知道这可能已被问了一百万次,但我找不到任何明确的东西.我正在建立一个网站,涉及可以建立项目列表的用户.我想知道在SQL表中存储项目的最佳方法是什么?
我想我是否需要为每个用户创建一个单独的表,因为在那里我看不到任何存储数组的方法.我认为这样效率会很低.
我想创建一个获取json响应的http get请求.在该会话响应中,我想将值存储到我的会话中.这怎么可以实现?
谢谢