fork download
  1. class StringToJson {
  2. public static void main(String[] args) {
  3. String input = "|'[]'|1007651102246_PC--chefgapparoniTTV|'[]'|1008939370770_PC--N3LAS|'[]'|1009614872477_PC--RalitsTwitch|1000071713191_PC--Twitch-Dnnnn"; // 請在這裡填入完整的字串
  4.  
  5. // 分割字串
  6. String[] entries = input.split("\\|");
  7.  
  8. // 遍歷每一個條目
  9. for (String entry : entries) {
  10. if (!entry.trim().isEmpty() && entry.contains("_")) {
  11. String[] parts = entry.split("_"); // 以 "_" 分割
  12. if (parts.length >= 2) {
  13. long uid = Long.parseLong(parts[0]); // 取得 uid
  14. String name = parts[1]; // 取得名稱
  15.  
  16. // 建立 JSON 物件的字串
  17. String jsonObject = String.format("{\"uid\":%d,\"name\":\"%s\",\"groupId\":1}", uid, name);
  18.  
  19. // 輸出 JSON 物件
  20. System.out.println(jsonObject);
  21. }
  22. }
  23. }
  24. }
  25. }
Success #stdin #stdout 0.08s 53868KB
stdin
Standard input is empty
stdout
{"uid":1007651102246,"name":"PC--chefgapparoniTTV","groupId":1}
{"uid":1008939370770,"name":"PC--N3LAS","groupId":1}
{"uid":1009614872477,"name":"PC--RalitsTwitch","groupId":1}
{"uid":1000071713191,"name":"PC--Twitch-Dnnnn","groupId":1}