I need to execute a Java code from php and pass a JSON string as an argument.
PHP part:
$json_arr["regrType"] = 3;
$json_arr["fund_id"] = 25106478;
$json_arr["factors"] = array(2,7,18,19);
$input = json_encode($json_arr);
exec("java StepRegTest.Main " . $input . " 2>&1", $output);
Java entry:
public class Main {
public static void main(String[] args) throws Exception {
Here is the problem: because the "main" constructor can take only String[] array and not a simple string, the Java script breaks the JSON string into array - like:
args[0] = "regrType:3"
args[1] = "fund_id:25106478"
args[2] = "factors:[2"
How can I force it to take the whole JSON input string? If I cannot find a way of getting the intact JSON string in Java, what can I do with arrays as JSON elements - see args[2]?
I could split the array part and use a different separator, but perhaps there is a more elegant way of doing this.
Thanks