Last active
December 18, 2018 15:45
-
-
Save jageshmaharjan/fc7aca156e8d8ae3582f2d8feb5395b4 to your computer and use it in GitHub Desktop.
Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AKMall Json parser extension | |
import org.json.simple.JSONObject; | |
import org.json.simple.parser.JSONParser; | |
import org.json.simple.parser.ParseException; | |
import java.io.*; | |
import java.util.ArrayList; | |
public class ClassicTechJsonReader { | |
public static void main(String[] args) throws IOException, ParseException { | |
ArrayList<JSONObject> arrayList = new ArrayList<>(); | |
String fPath = "result.json"; | |
File file = new File(fPath); | |
BufferedReader br = new BufferedReader(new FileReader(file)); | |
String line; | |
while ((line = br.readLine()) != null){ | |
String[] newLine = line.split("},"); | |
for (int i =0; i< newLine.length; i++){ | |
if (i == 0){ | |
newLine[i] = newLine[i].substring(1); | |
} | |
JSONParser parser = new JSONParser(); | |
JSONObject jsonObject = (JSONObject) parser.parse(newLine[i] +"}"); | |
arrayList.add(jsonObject); | |
} | |
} | |
WriteToFile(arrayList); | |
} | |
private static void WriteToFile(ArrayList<JSONObject> arrayList) throws IOException { | |
FileWriter fw = new FileWriter("AKMallParsedJson.json",true); | |
for (int i=0; i< arrayList.size(); i++) | |
{ | |
fw.write(String.valueOf(arrayList.get(i) + "\n")); | |
} | |
fw.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment