如何在“共享首选项”中使用Gson从JSON中删除特定集合?

时间:2018-07-05 05:56:10

标签: android json sharedpreferences

我想删除我使用Gson指定集合的​​属性。

我的代码:

   SharedPreferences sharedPreferences = parentActivity.getSharedPreferences(Accommodation.UPLOAD_ACCOMMODATION_DETAILS_ALL, MODE_PRIVATE);

        // Get saved string data in it.
        String userInfoListJsonString = sharedPreferences.getString(Accommodation.UPLOAD_ACCOMMODATION_DETAILS, "");

        // Create Gson object and translate the json string to related java object array.
        Gson gson = new Gson();

        Accommodation userInfoDtoArray = gson.fromJson(userInfoListJsonString, Accommodation.class);

        // Loop the UserInfoDTO array and print each UserInfoDTO data in android monitor as debug log.
        // Get each user info in dto.
        Accommodation userInfoDto = userInfoDtoArray;

我打印了Json,它具有以下内容:

  

{“ accommodationName1”:“绿色公寓”,
  “ accommodationName2”:“ Bangolor”,
  “ accommodationName3”:“ GHost house”,   “ imgAccommodation1”:“ / data / user / 0 / com.xxx.xxx / cache / cropped6900224487159235524.jpg”,   “ imgAccommodation2”:“ / data / user / 0 / com.xxx.xxx / cache / cropped3411178797945328810.jpg”,   “ imgAccommodation3”:“ / data / user / 0 / com.xxx.xxx / cache / cropped9128365945226539316.jpg”}

我可以使用以下代码获取值:

userInfoDto.accommodationName1;

它显示值:

  

绿色公寓

那么我如何删除该值的特定集合?

0 个答案:

没有答案