当前位置: 首页>>代码示例>>C#>>正文


C# Contact.toJson方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:52,代码来源:ContactSample.cs

示例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);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:39,代码来源:ContactSampleBatch.cs


注:本文中的Contact.toJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。