import org.json.JSONException;
import org.json.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class StudentMain {
public static void main(String[] args) {
String jsonString = "{\"name\":\"XYZ\", \"percentage\":95.90}";
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
Student student = gson.fromJson(jsonString, Student.class);
System.out.println(student.getPercentage());
}
}
package com.json;
class Student {
private String name;
private double percentage;
public Student(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPercentage() {
return percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
}
public String toString() {
return "Student [ name: "+name+", age: "+ percentage+ " ]";
}
}
Показывает 95,9, но я хотел отобразить 95,90. Может кто-нибудь помочь, пожалуйста?