package com.saic.grape.utils;
import java.util.Map;
import com.meidusa.fastjson.JSON;
import com.meidusa.fastjson.JSONObject;
import com.saic.grape.entity.KeyValue;
import com.saic.grape.entity.UserLogin;
/**
* Copyright (C),2014-4-22,
* @version 1.0
* @date 2014-4-22 javaBean转化为字符串公共类
* @author SHENBO
*/
public class FastJsonUtil
{
/**
* 将javabean转化为序列化的json字符串
* @param keyvalue
* @return
*/
public static Object beanToJson(KeyValue keyvalue) {
String textJson = com.meidusa.fastjson.JSON.toJSONString(keyvalue);
Object objectJson = JSON.parse(textJson);
return objectJson;
}
* 将string转化为序列化的json字符串
public static Object textToJson(String text) {
Object objectJson = JSON.parse(text);
* json字符串转化为map
* @param s
public static Map stringToCollect(String s) {
Map m = (Map) JSONObject.parSEObject(s);
return m;
* 将map转化为string
* @param m
public static String collectToString(Map m) {
String s = JSONObject.toJSONString(m);
return s;
* json字符串转化为javabean
public static UserLogin jsonToJavaBean(String s) {
UserLogin userLogin = JSONObject.parSEObject(s,UserLogin.class);
return userLogin;
public static void main(String[] args) {
String str = "{\"appCode\":\"Grape\",\"appVersion\":\"1.0\",\"deviceId\":\"236fa43ed352cc235\",\"sourceId\":\"1c1c1c\",\"userAccount\":\"13812345678\",\"userToken\":\"123456789\"}";
Map ma = FastJsonUtil.stringToCollect(str);
String ss = "{\"velModelId\":10000,\"velModelName\":\"奥迪\"}";
//LoginResultVelModel vd = FastJsonUtil.jsonToJavaBean(ss);
//System.out.println(vd.getVelModelName());
}