Java parsing JSON in args -


can me problem of parsing args in java?

i need read json data args in 2 formats(file, text arg). if arg path file json text, it's working.

in main method i'm reading args:

public static void main(string[] args){   string argtext = args[1] } 

but if i'm put arg json text (for example: {"server1":{"dname":"www.server.com","lat":"40","lng":"17"}) it's problem quotes, because in string argtext stored text without quotes:

system.out.println("text: " + argtext);  text: {server1:{dname:www.server.com,lat:40,lng:17}  

and method parsing json:

public static jsonobject parsejson(string argtext){   if (text.contains("{")){      //arg text , want store jsonobject       // how store text "    } else {      //argtext file....      // read file, put in new jsonobject      // works without problems.  }  return jsonobject } 

i don't know way read input args, file it's working , add reading form text.

if argtext contains escaped quotes \\\" everythig ok, don't have text in these format.

edit:

so don't have problem parsing json bud need method doing:

public static void(string quotedtext){    //do something...   system.out.print("output: " + text); } 

with in/out:

< '"text":"val1","val2","val3"' output: "text":"val1","val2","val3" 

in win system.out.print is:

'output: text:val1,val2,val3' 

if using library not suit needs, can make simple method covert it. add " after every {, before every }, , both before , after every , , :. there might ambiguity chars, why quotes supposed there @ first place.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -