2016-03-21 10 views
1

私はREST APIからデータをフェッチしてarraylistに保存するアンドロイドアプリケーションを持っています。しかし、今はREST APIからCouchbase Liteにデータを保存したいと思っています。これどうやってするの?もう1つのことは、REST APIのデータが変更された場合、その変更もCouchbase Liteに保存されます。助けてください。ここでAndroid REST API(JSON配列)からCouchbase Lite

は私のREST API JSON配列データ..です

[ 
{ 
    "ID": "1001", 
    "VAT": 0, 
    "barCode": "1023sewe", 
    "catagoryName": "Mobile", 
    "name": "Samsung Galaxy A5", 
    "purchasingPrice": 20000, 
    "quantity": 5, 
    "sellingPrice": 25000 
}, 
{ 
    "ID": "1002", 
    "VAT": 0, 
    "barCode": "215qwqw", 
    "catagoryName": "Mobile", 
    "name": "Iphone S5", 
    "purchasingPrice": 40000, 
    "quantity": 3, 
    "sellingPrice": 45000 
} 
] 
+1

はCouchbaseのサーバ自体がREST APIを使用しています。 Couchbase Liteを同期するには、Couchbase Serverを使用します。また、何か書類を読んだことがありますか?何か試した?あなたの質問にはコードはありません。 –

+0

私はMySQLデータベースを使用しています。では、このデータベースをcouchbaseサーバーでどのように使用できますか? –

+0

couchbase以外のサーバと同期したい場合は、カスタムのAndroid SyncAdapterを作成する必要があります。おそらくあなたがやりたいことよりも多くの仕事があります。クライアントとサーバー間でデータを同期させることは自明ではありません –

答えて

-2

あなたはCouchbaseのliteの中に挿入および更新操作を行うことができます。 CRUD操作について説明するこのリンクに従ってください。 http://developer.couchbase.com/documentation/mobile/1.2/develop/training/build-first-android-app/do-crud/index.html

挿入サンプル

private String createDocument(Database database) { 
    // Create a new document and add data 
    Document document = database.createDocument(); 
    String documentId = document.getId(); 
    Map<String, Object> map = new HashMap<String, Object>(); 
    map.put("name", "Big Party"); 
    map.put("location", "My House"); 
    try { 
      // Save the properties to the document 
      document.putProperties(map); 
    } catch (CouchbaseLiteException e) { 
    Log.e(TAG, "Error putting", e); 
    } 
    return documentId; 
} 

更新サンプル

private void updateDoc(Database database, String documentId) { 
    Document document = database.getDocument(documentId); 
    try { 
     // Update the document with more data 
     Map<String, Object> updatedProperties = new HashMap<String, Object>(); 
     updatedProperties.putAll(document.getProperties()); 
     updatedProperties.put("eventDescription", "Everyone is invited!"); 
     updatedProperties.put("address", "123 Elm St."); 
     // Save to the Couchbase local Couchbase Lite DB 
     document.putProperties(updatedProperties); 
    } catch (CouchbaseLiteException e) { 
      Log.e(TAG, "Error putting", e); 
    } 
} 
関連する問題