私はアンドロイドでmongoDBをサポートするアプリを開発中です。 JavaコードからMongoIDを作成し、それを私のサーバーに送信したいと思います。アンドロイドコードでMongoIDを作成するには?
は、ここで私は、このJSON
{
"_id" : ObjectId("59b7bcdf92e706382b00009f"),
"user_id" : "6bb82a99-bccd-4868-a799-55e7d28f969c",
"is_active" : false,
"_slugs" : [
"aaa"
],
"facility_name" : "aaa",
"industry_id" : 1,
"old_industry_id" : 1,
"established_date" : "1994-06-01",
"summary" : "this is test",
"facility_website" : "www.xxx.com",
"contact" : {
"_id" : ObjectId("4637gdff92jhsgd378364y"),
"info_type" : "PROFILE_INFO",
"name" : "xxxxxxxxxx",
"mobileNumber" : "xxxxxxxxx",
"email" : "[email protected]",
"shown_on_profile" : true
}}
を作成したい私のコード
あるしかし、私は私のJavaコードからこのJSONを取得しています。
{
"_id" : ObjectId("59b7bcdf92e706382b00009f"),
"user_id" : "6bb82a99-bccd-4868-a799-55e7d28f969c",
"is_active" : false,
"_slugs" : [
"aaa"
],
"facility_name" : "aaa",
"industry_id" : 1,
"old_industry_id" : 1,
"established_date" : "1994-06-01",
"summary" : "this is test",
"facility_website" : "www.xxx.com",
"contact" : {
"_id" : "{}",
"info_type" : "PROFILE_INFO",
"name" : "xxxxxxxxxx",
"mobileNumber" : "xxxxxxxxx",
"email" : "[email protected]",
"shown_on_profile" : true
}}
問題は
はここ
String _id = new JsonObject().toString(); // this is Gson.JsonObject() object
JSONObject contact = new JSONObject();
contact.put("_id", _id);
contact.put("info_type", "PROFILE_INFO");
contact.put("name", "User-1");
contact.put("mobileNumber", "xxxxxxxxxx");
contact.put("email", "[email protected]");
contact.put("shown_on_profile", true);
しかし、私の場合には、別のJsonObject内の多くのjsonObject.like JsonObjectがあります。 – Mehul
それで、あなたは複数の時間にそれを行う必要があります:オブジェクトを挿入し、objectIDを取得し、前のIDを持つ2番目のオブジェクトを送信し、2番目のオブジェクトIDを取得します... – fandro
@Mehul – fandro