Pagini recente » Cod sursa (job #3197858) | Cod sursa (job #1352275) | Cod sursa (job #1026630) | Cod sursa (job #305301) | Cod sursa (job #1359652)
import java.io.*;
import java.util.Scanner;
import java.util.regex.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileInputStream("convertor.in"));
sc.useDelimiter("}\\s*,");
PrintWriter writer = new PrintWriter("convertor.out");
// Un obiect are mai multe intrari, iar fiecare intrare are o pereche cheie-valoare
boolean first = true;
while (sc.hasNext()) {
String obj = sc.next();
String[] entries = obj.split("\\s*,\\s*");
if (first) {
for (String entry : entries) {
String[] entry2 = entry.split("\\s*:\\s*");
Pattern patternKey = Pattern.compile("\"([a-zA-Z0-9\\s]+)\"");
Matcher matcher = patternKey.matcher(entry2[0]);
matcher.find();
String key = matcher.group(0).replaceAll("\"", "");
//System.out.print(key + ",");
writer.write(key + ",");
}
first = false;
}
//System.out.println();
writer.write("\n");
for (String entry : entries) {
String[] entry2 = entry.split("\\s*:\\s*");
String value = entry2[1].replaceAll("[\"}\\]]", "").trim();
//System.out.print(value + ",");
writer.write(value + ",");
}
}
sc.close();
writer.close();
}
}