Java 分裂逻辑中的几个问题

Java 分裂逻辑中的几个问题,java,string,stringtokenizer,Java,String,Stringtokenizer,嗨,我有下面的字符串,我必须拆分并放入地图。通过字符串标记器或.split方法进行拆分时,我没有得到想要的结果。下面是我的字符串 {"errorCode":"specialChars.allowed","errorParams":["a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space"]} 我想要 Key:errorCode Value:specialChars.allowed Key:errorParams Value:[ "a-zA-Z

嗨,我有下面的字符串,我必须拆分并放入地图。通过字符串标记器或.split方法进行拆分时,我没有得到想要的结果。下面是我的字符串

{"errorCode":"specialChars.allowed","errorParams":["a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space"]}
我想要

 Key:errorCode Value:specialChars.allowed 
Key:errorParams Value:[
  "a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space"
]

由于输入字符串是JSON字符串,因此可以使用Gson API将其转换为映射

String str = “{‘errorCode’:’specialChars.allowed’,’errorParams’,’[“a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space”]’}”;
Type type = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> myMap = new Gson().fromJson(str,type);
String str=“{'errorCode':'specialChars.allowed','errorParams','[“a-zA-Z0-9^][{{{124;}=~!\“\$%&()*+,-.:'\/?@space']}”;
Type Type=new-TypeToken(){}.getType();
Map myMap=new Gson().fromJson(str,type);

如果您觉得我的答案可以解决您的问题,请点击勾号,接受我的答案。