简体   繁体   中英

How to change a string from a json file to a random string

I have json file that i need to change a word from this json and i want to change string word to a random string before i do that i need to know how to write and read json file from android studio or intellij and after that what to write to change the string.

the json file look like this:

  {
      "Bath" : {
        "-KNYTXnET3oJPOCG64fd" : {
          "autor" : "test467",
          "locationBathALon" : -34.770635,
          "locationBathBLat" : 150.8112166,
          "messageNameBath" : "Park Road Reserve",
          "ratebath" : "4.0"
        },
        "-KNYTXnET3oJPOCG64fd" : {
          "addressBath" : "George Hanley Drive",
          "autor" : "test467",
          "locationBathALon" : -34.40937488,
          "locationBathBLat" : 150.89999737,
          "messageNameBath" : "The Lagoon Seafood Restaurant",
          "ratebath" : "4.0"
        },
        "-KNYTXnET3oJPOCG64fd" : {
          "autor" : "test467",
          "locationBathALon" : -34.42711139,
          "locationBathBLat" : 150.89886635,
          "messageNameBath" : "Wollongong City Council and Library",
          "ratebath" : "4.0"
            }
      }
    }

I want to change the string "KNYTXnET3oJPOCG64fd" to a random string that for everyone be a other string. i prefer to do that with some software that do that. If software like this not exist, what i need to write to do that in java or android? I'll be happy for some example code

I guess you want this

Generate random String

public String randomString(int len){
        final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!@#$%&*";
        SecureRandom rnd = new SecureRandom();
        StringBuilder sb = new StringBuilder( len );
        for( int i = 0; i < len; i++ )
            sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
        return sb.toString();
    }


String json = json.replace("-KNYTXnET3oJPOCG64fd",randomString("-KNYTXnET3oJPOCG64fd".length()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM