前台jquery转换

字符串转换成对象
$.parseJSON( jsonstr );
JSON.parse(jsonstr);
eval('(' + jsonstr + ')');

对象转换成字符串 
JSON.stringify(jsonobj);


String转JSONObject
JSONObject.fromObject(jsonMessage)

String转JSONArray
JSONArray.fromObject(jsonMessage)


JSONObject——String
myJsonObject.toString();

JSONArray——String
myJsonArray.toString()

JSONArray转JSONObject
myJsonArray.getJSONObject(i)

Map转JSONObject
JSONObject.fromObject( map )

Map转JSONArray
JSONArray.fromObject(map)

List转JSONArray
 JSONArray.fromObject( list )

JSONArray转List
 (List)jsonArray

扫描二维码关注公众号,回复: 2531235 查看本文章


json转换为list
gson.fromjson([json],List.class)


String转date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = sdf.parse("2016-10-20 11:27:08");
System.out.println(date);


数组转换为json
JSON.stringify();

时间转字符串
[sql] 预览复制
select date_format(now(), '%Y-%m-%d');  
  
#结果:2016-01-05  
时间转时间戳
[sql] 预览复制
select unix_timestamp(now());  
  
#结果:1452001082  
字符串转时间
[sql] 预览复制
select str_to_date('2016-01-02', '%Y-%m-%d %H');  
  
#结果:2016-01-02 00:00:00  
字符串转时间戳
[sql] 预览复制
select unix_timestamp('2016-01-02');  
  
#结果:1451664000  
时间戳转时间
[sql] 预览复制
select from_unixtime(1451997924);  
  
#结果:2016-01-05 20:45:24  
时间戳转字符串
[sql] 预览复制
select from_unixtime(1451997924,'%Y-%d');  
  
//结果:2016-01-05 20:45:24  

猜你喜欢

转载自blog.csdn.net/AinUser/article/details/81296182
今日推荐