Can you anyone help me with problem of parsing args in java?
I need to read JSON data by args in two formats(file, text arg). If an arg is path to file with 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 to arg some JSON text (for example: {"server1":{"dname":"www.server.com","lat":"40","lng":"17"}) it's problem with quotes, because in
String argText is stored text without quotes:
System.out.println("Text: " + argText);
Text: {server1:{dname:www.server.com,lat:40,lng:17}
And method for parsing JSON:
public static JSONObject parseJSON(String argText){
if (text.contains("{")){
//arg is text and I want to store it as JSONObject
// how to store text with "
} else {
//argText is file....
// read file, put in new JSONObject
// it works without any problems.
}
return JsonObject
}
I don't know it is the good way to read input args, but for file it's working and I would to add reading form the text.
If argText contains escaped quotes \\\" everythig is OK, but I don't have text in these format.
EDIT:
So I don't have problem with parsing JSON bud I need some method that 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'