I have thousand of strings in Json and I wanted to convert into xml(strings.xml) .Is there any short way to do that ? plugins ? or I have to do it one by one?
Asked
Active
Viewed 995 times
0
-
1Do you want to do in within your program? Or do you just convert a json file to xml for each entries? – stinepike Dec 08 '20 at 20:26
-
just want to convert which give me above results and same i could paste it in `strings.xml` – chand mohd Dec 08 '20 at 20:34
2 Answers
0
If you want to convert the json to xml in your app, you can use any existing library. This answer refers to one such.
If you just want to simply convert a json contents to xml, you can use any online converter. This one came first in my google search result. (But I would check the site's reliability before uploading any sensitive data)

stinepike
- 54,068
- 14
- 92
- 112
0
You can read the entire JSON into a String
object, and get the XML representation with Regex
and .replace()
method Of a String
Here is a smaple
val json = """{
"text_download_complete":"your file is downloaded"
}"""
val xml = json.replace("\\{\\s*".toRegex(), "<string name=")
.replace(":\\s*\"".toRegex(), ">")
.replace("\"\\s*\\}".toRegex(), "</string>")
Log.d("LOG_TAG", "onCreate: XML:\n$xml")
You can also read the JSON file instead of coping the entire file into a String...
I believe that won't be the optimum solution, but I think it would be a one shot task, and just wanted to be simple rather than looking at performance.

Zain
- 37,492
- 7
- 60
- 84