gson£¨JSON×Ö·û´®×ª»»³ÉÒ»¸öÏàµÈµÄJava¶ÔÏó£©
Ä¿Ç°´ó¶àÊýʹÓÃgsonµÄ»¹ÒªÇóÔÚjavaÀàÖÐʹÓÃjava annotation£¬²»ÍêÈ«Ö§³ÖPOJO¡£
GsonÕâ¸öJavaÀà¿â¿ÉÒÔ°ÑJava¶ÔÏóת»»³ÉJSON£¬Ò²¿ÉÒÔ°ÑJSON×Ö·û´®×ª»»³ÉÒ»¸öÏàµÈµÄJava¶ÔÏó¡£GsonÖ§³ÖÈÎÒ⸴ÔÓJava¶ÔÏó°üÀ¨Ã»ÓÐÔ´´úÂëµÄ¶ÔÏó¡£
´úÂëÀý×Ó
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.test.json;
import com.google.gson.Gson;
/**
*
* @author ann
*/
public class JsonConverter {
public void toPerson(){
String json = "{'data1':100,'data2':'hello','id':1}";
Gson gson = new Gson();
Person p = gson.fromJson(json, Person.class);
System.out.println(" p :" +p.getId());
System.out.println("p:"+p.getName());
}
public void toJsonString(){
Person p = new Person();
p.setId(1);
Gson gson = new Gson();
String s = gson.toJson(p,Person.class);
System.out.println("s"+s);
}
public static void main(String[] args) {
JsonConverter convert = new JsonConverter();
convert.toPerson();
//convert.toJsonString();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.test.json;
/**
*
* @author ann
*/
public class Person {
private int id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
ÏÂÔØhttp://code.google.com/p/google-gson/
Ïà¹ØÎĵµ£º
±àÕß°´£ºJavaÄÚ´æй©ÊÇÿ¸öJava³ÌÐòÔ±¶¼»áÓöµ½µÄÎÊÌ⣬³ÌÐòÔÚ±¾µØÔËÐÐÒ»ÇÐÕý³££¬¿ÉÊDz¼Êðµ½Ô¶¶Ë¾Í»á³öÏÖÄÚ´æÎÞÏÞÖƵÄÔö³¤£¬×îºóϵͳ̱»¾£¬ÄÇôÈç
ºÎ×î¿ì×îºÃµÄ¼ì²â³ÌÐòµÄÎȶ¨ÐÔ£¬·Àֹϵͳ±ÀÅÌ£¬×÷ÕßÓÃ×ÔÒѵÄÇ×Éí¾ÀúÓë¸÷λÍøÓÑ·ÖÏí½â¾öÕâЩÎÊÌâµÄ°ì·¨¡£
×÷ΪInternet×îÁ÷Ðеı ......
Ò» Ï̵߳Ļù±¾¸ÅÄî
Ïß³ÌÊÇÒ»¸ö³ÌÐòÄÚ²¿µÄ˳Ðò¿ØÖÆÁ÷.Ò»¸ö½ø³ÌÏ൱ÓÚÒ»¸öÈÎÎñ,Ò»¸öÏß³ÌÏ൱ÓÚÒ»¸öÈÎÎñÖеÄÒ»ÌõÖ´Ðз¾¶.
¶à½ø³Ì:ÔÚ²Ù×÷ϵͳÖÐÄÜͬʱÔËÐжà¸öÈÎÎñ(³ÌÐò)
¶àÏß³Ì:ÔÚͬһ¸öÓ¦ÓóÌÐòÖÐÓжà¸ö˳ÐòÁ÷ͬʱִÐÐ
JavaµÄÏß³ÌÊÇͨ¹ýjava.lang.ThreadÀàÀ´ÊµÏÖµÄ
JVMÆô¶¯Ê±»áÓÐÒ»¸öÓÉÖ÷·½·¨(public static void main( ......
ÔÚ·ÇjavaÐéÄâ»úÏÂÔËÐÐmatlab¾Ý˵¿ÉÒÔÀ©´óÄÚ´æ,Æô¶¯·ÇjavaÐéÄâ»úÏÂÔËÐÐ matlabµÄ·½·¨ÓУº
Ò».
1¡¢ÓÒ½¨µãmatlab¿ì½Ý·½Ê½£¬Ñ¡ÊôÐÔ ......