I want to read the string as JSON format (it should not be JSON, but it is similar to JSON format) and present it in hashMap (key: Keyword, value: COUNT)
for example, suppose I have a String.
String s ={"Welcome":1,"Hi":2,"Hello":1,"Jin":1};
Then make it a classification (for the key Hashmap β word, value β number). The end result will be approximately as shown below.
HashMap<String,String> result;
result.get("Jin");
result.get("Hi");
but my codes, this is not going the right way.
JSONParser parser = new JSONParser();
Object obj = parser.parse(s);
JSONArray array = new JSONArray();
array.add(obj);
System.out.println(array.get(0)); //output: {"Welcome":1,"Hi":2,"Hello":1,"Jin":1}
is it possible with json? or should I smash them one by one? (e.g. split them into "," and ":" ... so on)
Please give me your good advice.
source
share