本文整理汇总了C#中Contact.toJson方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.toJson方法的具体用法?C# Contact.toJson怎么用?C# Contact.toJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contact
的用法示例。
在下文中一共展示了Contact.toJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
public void run() {
try {
// Login
string token = Query.login("[email protected]", "demobiz");
Query query = new Query(token);
// 1. Select All Contacts
JSONObject[] items = query.select(Contact.TABLE, null);
foreach (JSONObject item in items) {
// get Contact object from Json for easy record values manipulation
Contact contact = Contact.fromJson(item);
Console.WriteLine("Name: " + contact.name + ", email:" + contact.email + ", mobile: " + contact.mobile);
}
// 2. Create a new contact
Contact newContact = new Contact();
newContact.id = "MyUniqueId";
newContact.name = "John Smith";
newContact.email = "[email protected]";
newContact.mobile = "6979 0486";
newContact.jobtitle = "CTO";
query.insert(Contact.TABLE, newContact.toJson());
// Verify that the contact has been correctly inserted by selecting it again
JSONObject obj = query.selectId(Contact.TABLE, newContact.id);
if (obj != null) {
Console.WriteLine("Contact: " + obj.ToString());
}
// 3. Update Contact
Contact updatedContact = new Contact();
updatedContact.mobile = "111111";
query.updateId(Contact.TABLE, newContact.id, updatedContact.toJson());
// Verify that the contact has been correctly updated
obj = query.selectId(Contact.TABLE, newContact.id);
if (obj != null) {
Console.WriteLine("Contact Mobile:" + obj.getString("mobile"));
}
// 4. Delete Contact
query.deleteId(Contact.TABLE, newContact.id);
// Verify that the contact has been correctly updated
obj = query.selectId(Contact.TABLE, newContact.id);
if (obj == null) {
Console.WriteLine("Contact has been deleted");
}
} catch (Exception e) {
Console.WriteLine("Error:" + e.Message);
}
}
示例2: run
public void run() {
try {
// Login
string token = Query.login("[email protected]", "demobiz");
Query query = new Query(token);
// 1. Start a batch operation
query.beginBatch();
for (var i = 1; i < 5; i++) {
// 2. Create a new contact
Contact contact = new Contact();
contact.id = "JOHN_ID" + i;
contact.name = "John " + i;
contact.email = "John" + i + "@gmail.com";
// this add the insert query to the internal batch query buffer
query.insert(Contact.TABLE, contact.toJson());
}
// this performs one HTTPS web service call and executes all previous queries
query.commitBatch();
// 2. Now Batch Update the Records
query.beginBatch();
for (var i = 1; i < 5; i++) {
Contact updatedValues = new Contact();
updatedValues.email = "john" + i + "@yahoo.com";
query.updateId(Contact.TABLE, "JOHN_ID" + i, updatedValues.toJson());
}
query.commitBatch();
// 3. Now Batch Delete the Records
query.beginBatch();
for (var i = 1; i < 5; i++) {
query.deleteId(Contact.TABLE, "JOHN_ID" + i);
}
query.commitBatch();
} catch (Exception e) {
Console.WriteLine("Error:" + e.Message);
}
}