-2

Sample JSON getting from my service

{
    "appID": 1,
    "appName": "app1",
    "screenID": 1,
    "screens": "Login",
    "textID": 1,
    "keyName": "TEXT_1",
    "text_EN": "USERNAME",
    "text_DE": null,
    "text_PE": null
},
{
    "appID": 1,
    "appName": "app1",
    "screenID": 1,
    "screens": "Login",
    "textID": 2,
    "keyName": "TEXT_2",
    "text_EN": "PASSWORD",
    "text_DE": null,
    "text_PE": null
},
{
    "appID": 1,
    "appName": "app1",
    "screenID": 1,
    "screens": "Login",
    "textID": 3,
    "keyName": "TEXT_3",
    "text_EN": "Fingerprint Login",
    "text_DE": null,
    "text_PE": null
}

And I want to write the in text file as

"TEXT_1"="USERNAME";

"TEXT_2"="PASSWORD";

"TEXT_3"="Fingerprint Login";

Community
  • 1
  • 1

1 Answers1

0

Try below using org.json:

String json = ""; // Your jsonArray
JSONObject result = new JSONObject();
JSONArray arr = new JSONArray(json);
for(int i = 0; i< arr.length() ; i++) {
  JSONObject jsonObj = arr.getJSONObject(i);
  result.put(jsonObj.getString("keyName"), jsonObj.getString("text_EN"));
}
System.out.println(result);

Result:

{"TEXT_1":"USERNAME","TEXT_2":"PASSWORD","TEXT_3":"Fingerprint Login"}
Aditya Narayan Dixit
  • 2,105
  • 11
  • 23