这是一个奇怪的问题.这是我的代码
String reply = listen.executeUrl("http://localhost:8080/JavaBridge/reply.php);
Run Code Online (Sandbox Code Playgroud)
executeUrl作为String对象返回reply.php文件返回的任何内容.现在出现了问题.在reply.php我返回一个PHP数组,回复是一个字符串.
当我做
System.out.println("Reply = "+reply);
Run Code Online (Sandbox Code Playgroud)
我明白了
Reply = array(2) { [0]=> string(14) "Dushyant Arora" [1]=> string(19
) "@dushyantarora13 hi"}
Run Code Online (Sandbox Code Playgroud)
但回复仍然是一个字符串.如何将其转换为String数组或Array.
您可能希望尝试在reply.php中返回JSON对象,然后使用JSON库将其导入Java.
reply.php:
<?
...
echo json_encode($yourArray);
Run Code Online (Sandbox Code Playgroud)
在您的Java代码中:
...
JSONArray reply = new JSONArray(listen.executeUrl("http://localhost:8080/JavaBridge/reply.php"));
Run Code Online (Sandbox Code Playgroud)