❶ Jackjson如何將反序列化的數據傳到jsp頁面
如果你使用的是servlet,可以先保存數據到request: request.setAttribute("key",反序列化對象數據);然後forward到jsp頁面:request.getRequestDispatcher("jsp頁面").forward(request,response);
在jsp中獲取數據request.getAttribute("key");使用。
當然,你也可以使用session、application 暫存數據,但是別忘了使用後remove他們。
❷ springmvc jackon 為什麼不返回json
SpringMvc配置:
<!--啟動SpringMVC的註解功能,完成請求和註解POJO的映射-->
<beanclass="org.springframework.web.servlet.mvc.annotation.">
<propertyname="messageConverters">
<list>
<!--json轉換器-->
<refbean=""/>
</list>
</property>
</bean>
<beanclass="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<propertyname="messageConverters">
<list>
<refbean=""/>
</list>
</property>
</bean>
<beanid=""
class="org.springframework.http.converter.json.">
<propertyname="supportedMediaTypes">
<list>
<beanclass="org.springframework.http.MediaType">
<constructor-argindex="0"value="text"/>
<constructor-argindex="1"value="plain"/>
<constructor-argindex="2"value="UTF-8"/>
</bean>
<beanclass="org.springframework.http.MediaType">
<constructor-argindex="0"value="*"/>
<constructor-argindex="1"value="*"/>
<constructor-argindex="2"value="UTF-8"/>
</bean>
<beanclass="org.springframework.http.MediaType">
<constructor-argindex="0"value="text"/>
<constructor-argindex="1"value="*"/>
<constructor-argindex="2"value="UTF-8"/>
</bean>
<beanclass="org.springframework.http.MediaType">
<constructor-argindex="0"value="application"/>
<constructor-argindex="1"value="json"/>
<constructor-argindex="2"value="UTF-8"/>
</bean>
</list>
</property>
</bean>
Controller代碼
@RequestMapping(value="update",method=RequestMethod.POST)
@ResponseBody
publicMap<String,Object>update(SOUserentity,){
LonguserId=entity.getId();
Longuid=TokenManager.getUserId();
if(StringUtils.isBlank(userId,uid)||!uid.equals(userId)){
resultMap.put("status",500);
resultMap.put("message","非法修改!");
}else{
Stringname="portrait/"+userId;
Stringportrait=ImageManager.saveImages(name,request);
if(StringUtils.isNotBlank(portrait)){
entity.setPortrait(portrait);
}
userService.updateByPrimaryKeySelective(entity);
resultMap.put("status",200);
resultMap.put("message","修改成功!");
entity=userService.selectByPrimaryKey(userId);
//更新
TokenManager.login(entity);
}
returnresultMap;
}
❸ json 中如何使用@JsonIgnore
json 中使用@方法如下。
❹ 怎麼返回得到的gson.fromjson
import com.google.gson.Gson;
public class TestJson
{
private int age;
private String name;
public String show()
{
return new String("name:" + name + "/age:" + age);
}
public static void main(String[] args)
{
String[] source =new String[]{
"",
"abc",
"{}",
"{\"nick_name\":\"Jack\"}",
"{\"name\":\"Anna\",\"id\":5}",
"{\"name\":\"Pluto\",\"age\":15,\"id\":10}"
};
Gson g=new Gson();
TestJson x=null;
StringBuffer info=null;
for(int i=0;i<source.length;i++)
{
info=new StringBuffer();
info.append(i).append(":").append(source[i]).append("\n\t");
try
{
x=g.fromJson(source[i], TestJson.class);
info.append((x == null) ? "NULL" : x.show());
}catch(Exception e)
{
info.append(e.getClass().getName());
}
System.out.println(info.toString());
}
}
}
❺ 如何給Swift字典Dictionary增加空值
有些情況下在Swift中想讓Dictionary某個Key為空值,比如在與伺服器交互時,有些參數無論有沒有值必須要求傳.但如果給字典的key賦值為nil,字典則會移除這個鍵值對,如下:
var dict1=Dictionary<String,AnyObject>()
dict1["name"]="Jack"
dict1["age"]=16
dict1["nickname"]=nil
println(dict1) //"[age: 16, name: Jack]"
let jsonData1 = NSJSONSerialization.dataWithJSONObject(dict1, options: NSJSONWritingOptions.allZeros, error: nil)!
let jsonString1 = NSString(data: jsonData1, encoding: NSUTF8StringEncoding)!
println(jsonString1) //"{"age":16,"name":"Jack"}"
如果像要字典的值為NULL,可以使用NSNULL,這樣就可以達到像要的效果了:
var dict2=Dictionary<String,AnyObject>()
dict2["name"]="Jack"
dict2["age"]=16
dict2["nickname"]=NSNull()
println(dict2) //[age: 16, nickname: <null>, name: Jack]
let jsonData2 = NSJSONSerialization.dataWithJSONObject(dict2, options: NSJSONWritingOptions.allZeros, error: nil)!
let jsonString2 = NSString(data: jsonData2, encoding: NSUTF8StringEncoding)!
println(jsonString2) //{"age":16,"nickname":null,"name":"Jack"}
❻ elasticsearch 2.3.1 要使用什麼版本的jackjson
Elasticsearch是一個全文搜索引擎。安裝Elasticsearch時需要先安裝Java。
要求的jdk版本1.7以上的。
以下是官方文檔:
Elasticsearch requires at least Java 7. Specifically as of this writing, it is recommended that you use the Oracle JDK version 1.8.0_25. Java installation varies from platform to platform so we won』t go into those details here. Oracle』s recommended installation documentation can be found on Oracle』s website. Suffice to say, before you install Elasticsearch, please check your Java version first by running (and then install/upgrade accordingly if needed): 需要jdk1.7 以上版本