0

JsonToStrings

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?

chand mohd
  • 2,363
  • 1
  • 14
  • 27

2 Answers2

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