2017-03-14 54 views
1

我是android中的新手。我想在字符串修改這個值,如果{「性別」:1}是女性,{「性別」:2}是男性 這裏是我的代碼提前 感謝翻新改變json值並顯示

模型類

public class people{ 
@SerializedName("gender") 
@Expose 
private Integer gender; 
public Integer getGender() { 
    return gender; 
} 

public void setGender(Integer gender) { 
    this.gender = gender; 
     } 
    } 

接口

public interface ApiInterface{ 
    @GET("person/{person_id}") 
    Call<People> getPeopleDetails(@Path("person_id") int personId, 
           @Query("api_key") String apikey); 
     } 

從改型

ApiInterface apiInterface = ApiClient.getRetrofit().create(ApiInterface.class); 
    Call<People> call = apiInterface.getPeopleDetails(personId,getResources().getString(R.string.api_key)); 
    call.enqueue(new Callback<People>() { 
     @Override 
     public void onResponse(Call<People> call, Response<People> response) { 

      People peopleResponse = response.body(); 

      v.biography.setText(peopleResponse.getBiography()); 
      v.dob.setText(String.valueOf(peopleResponse.getBirthday())); 

      v.gender.setText(String.valueOf(peopleResponse.getGender())); 

      v.homepage.setText(String.valueOf(peopleResponse.getHomepage())); 
      v.imdbid.setText(peopleResponse.getImdbId()); 
      v.popularity.setText(String.valueOf(peopleResponse.getPopularity())); 
      v.place_of_birth.setText(peopleResponse.getPlaceOfBirth()); 
      Picasso.with(getApplicationContext()).load("http://image.tmdb.org/t/p/w185"+peopleResponse.getProfilePath()).resize(150,220).into(v.personImageView); 

     } 

     @Override 
     public void onFailure(Call<People> call, Throwable t) { 

      t.printStackTrace(); 
     } 
    }); 

回答

0

響應沒有新的

if("1".equals(String.valueOf(peopleResponse.getGender())){ 
v.gender.setText("female")); 
} else { 
    v.gender.setText("male")); 
} 
+0

感謝兄弟對我真的很有幫助 – prem

+0

btw這不是改造其基本的Java的一部分 –