How to Convert following String to Json using Java? -


i need convert following string json format.

below input expected output reference.

input:

employee driver report - edr -------------------------------- employee nbr: 123480 employee type: di cat: upl driver license: pp3p30 plate: rowp part number: 1006096 

output:

{ "employee nbr": "123480", "employee type": "di", "cat": "upl", "driver license": "pp3p30", "plate": "rowp", "part number": "1006096", } 

sample code:

map<string, string> keyvaluemap = new hashmap<string, string>(); string[] lines = rawtext.split(system.getproperty("line.separator")); for(string line: lines) { .......    keyvaluemap.put(keyandvalues[i], keyandvalues[i + 1]); } gson gson = new gsonbuilder().setprettyprinting().create(); string json = gson.tojson(keyvaluemap); 

could please me on how resolve this?

thanks in advance.

for each line get, have parse using : , (space) delimiters.

i'll let search correct regex use , ask if needed ;)


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -