我想知道是否有办法将mongo集合从php脚本返回到java。假设我在我的Android应用程序中连接到url,如下所示:
URL url = new URL(SERVER_ADDRESS + "db.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
其中db.php是这样的:
$db = new Mongo('mongodb://.../test');
$c_things = $db->things;
其中$c_things
是集合。
我可以在我的应用中检索/解析$c_things
MongoCollection<Document> format
吗?如果有一个教程,非常欢迎。
答案 0 :(得分:0)
在php端使用bson_encode生成一个BSON字符串并返回该字符串。然后在Java端用户他mongo DB BSON解码功能将其重新转换为集合。
答案 1 :(得分:0)
执行此操作的最佳做法是使用JSONArray尝试从Server返回,并使用Retrofit正确使用服务。