Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created June 3, 2014 11:24
Show Gist options
  • Save tos-kamiya/1ce25fa58d1524129d79 to your computer and use it in GitHub Desktop.
Save tos-kamiya/1ce25fa58d1524129d79 to your computer and use it in GitHub Desktop.
Jsonic library sample
package jsonictest;
public class AB {
private int a;
private String b;
public AB() { // 必要
}
public AB(int a, String b) { // 任意
this.a = a;
this.b = b;
}
public int getA() { // 必要
return a;
}
public void setA(int a) { // 必要
this.a = a;
}
public String getB() { // 必要
return b;
}
public void setB(String b) { // 必要
this.b = b;
}
public String toString() { // 任意
return "AB(" + a + ",\"" + b + "\")";
}
}
package jsonictest;
import net.arnx.jsonic.JSON;
public class Main {
public static void main(String[] args) {
AB ab = new AB(1, "boo");
String tmp = JSON.encode(ab);
System.out.println("AB(1, \"boo\") -> " + tmp);
String js = "{\"a\":10,\"b\":\"CD\"}";
AB cd = JSON.decode(js, AB.class);
System.out.println(cd.toString() + " <- " + js);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment