1
package se.msc.android.droidcouch;
3
import java.util.Iterator;
5
import org.json.JSONException;
6
import org.json.JSONObject;
7
import org.json.JSONStringer;
9
public class CouchJsonDocument implements ICouchDocument {
12
public JSONObject Obj;
14
public CouchJsonDocument(String json, String id, String rev) throws JSONException
16
Obj = new JSONObject(json);
21
public CouchJsonDocument(String json, String id) throws JSONException
23
Obj = new JSONObject(json);
27
public CouchJsonDocument(String json) throws JSONException
29
Obj = new JSONObject(json);
32
public CouchJsonDocument(JSONObject doc)
37
public CouchJsonDocument()
39
Obj = new JSONObject();
42
public String toString()
44
return Obj.toString();
49
public void WriteJson(JSONStringer writer)
51
Iterator i = Obj.keys();
53
String key = (String) i.next();
55
writer.key(key).value(Obj.get(key));
56
} catch (JSONException e) {
57
// TODO Auto-generated catch block
63
// Presume that Obj has _id and _rev
64
public void ReadJson(JSONObject obj)
71
return Obj.optString("_rev");
73
public void Rev(String newValue)
76
Obj.put("_rev", newValue);
77
} catch (JSONException e) {
78
// TODO Auto-generated catch block
85
return Obj.optString("_id");
87
public void Id(String newValue)
90
Obj.put("_id", newValue);
91
} catch (JSONException e) {
92
// TODO Auto-generated catch block