想要实现@SerializedName Gson我不知道如何实现 Gson请帮我解释如何实现@SerializedName GSON
public class ModelClass {
@SerializedName("longi")
public String longitudeServer;
@SerializedName("lati")
public String latitudeServer;
@SerializedName("uniqueid")
public String uniqueidSserver;
public ModelClass(){
// blank constructor is required
}
public String getLongitude(){
return longitudeServer;
}
public String getLatitude(){
return latitudeServer;
}
public String getUniqueId(){
return uniqueidSserver;
}
//... More setter and getter here
}
答案 0 :(得分:1)
1:-problem是跳转当前指针。
公共类中的creat方法addMarker()MainActivity扩展了AppCompatActivity
private void addMarker() {
try {
//ArrayList list = new ArrayList<>();
//TODO: remove previus markers
if (marker != null) {
mMap.clear();
Toast.makeText(getApplicationContext(), "Remove", Toast.LENGTH_LONG).show();
}
for (LatLng object : latLngList)
marker = mMap.addMarker(new MarkerOptions().title("User Name").position(object).icon(BitmapDescriptorFactory.fromResource(R.drawable.female4)));
System.out.println(marker.getPosition() + " Marker position.......");
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Error ", Toast.LENGTH_LONG).show();
// mMap.clear();
}
}
并在
中调用它 if (servicesOK()) {
setContentView(R.layout.activity_map);
if (initMap()) {
// gotoLocation(SEATTLE_LAT, SEATTLE_LNG, 15);
mLocationClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mLocationClient.connect();
mMap.setMyLocationEnabled(true);
} else {
Toast.makeText(this, "Map not connected!", Toast.LENGTH_SHORT).show();
}
addMarker();
} else {
setContentView(R.layout.activity_main);
}
在OnPostExecute中
protected void onPostExecute(Boolean result) {
// dialog.cancel();
// adapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), "Receicve data from server", Toast.LENGTH_LONG).show();
if (result == false) {
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
// try {
// //ArrayList list = new ArrayList<>();
// //TODO: remove previus markers
// if (marker != null) {
// mMap.clear();
// Toast.makeText(getApplicationContext(), "Remove", Toast.LENGTH_LONG).show();
//
// }
// for (LatLng object : latLngList)
//
// marker = mMap.addMarker(new MarkerOptions().title("User Name").position(object).icon(BitmapDescriptorFactory.fromResource(R.drawable.female4)));
//
// System.out.println(marker.getPosition() + " Marker position.......");
// } catch (Exception e) {
// Toast.makeText(MainActivity.this, "Error ", Toast.LENGTH_LONG).show();
// // mMap.clear();
// }
}
}
答案 1 :(得分:1)
虚拟使用SerializedName
@SerializedName("Savings")
private String savings;
您需要添加
编译com.google.code.gson:gson:2.3.1&#39;
build.gradle中的内部依赖项