Hi all,
Please help me this situation, if i have codes like that:
[HIGH]
public void writeJSON() {
JSONObject object = new JSONObject();
try {
object.put("name", "Jack Hack");
object.put("score", new Integer(200));
object.put("current", new Double(152.32));
object.put("nickname", "Hacker"); } catch (JSONException e) {
e.printStackTrace();
}
System.out.println(object); } [/HIGH]
I don't want hardcode such as "name, score, current, nickname".
I would like to use enums or constants.
With enum:
[HIGH]
public enum PersonEnum {
Name("name"),
Score("score"),
Current("current"),
Nickname("nickname");
private String value
PersonEnum (String value) {
this.value = value;
}
public String getValue(){
return value;
}
}
[/HIGH]
Please help me this situation, if i have codes like that:
[HIGH]
public void writeJSON() {
JSONObject object = new JSONObject();
try {
object.put("name", "Jack Hack");
object.put("score", new Integer(200));
object.put("current", new Double(152.32));
object.put("nickname", "Hacker"); } catch (JSONException e) {
e.printStackTrace();
}
System.out.println(object); } [/HIGH]
I don't want hardcode such as "name, score, current, nickname".
I would like to use enums or constants.
With enum:
[HIGH]
public enum PersonEnum {
Name("name"),
Score("score"),
Current("current"),
Nickname("nickname");
private String value
PersonEnum (String value) {
this.value = value;
}
public String getValue(){
return value;
}
}
[/HIGH]
With constant:
[HIGH]
public static final String Name = "name"; ........etc.
[/HIGH]
So, what way should I use if i have many json objects similar above?
How about the performance ? I appreciate any advice on the problem.
[HIGH]
public static final String Name = "name"; ........etc.
[/HIGH]
So, what way should I use if i have many json objects similar above?
How about the performance ? I appreciate any advice on the problem.