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


C# JSONObject.putDate方法代码示例

本文整理汇总了C#中JSONObject.putDate方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.putDate方法的具体用法?C# JSONObject.putDate怎么用?C# JSONObject.putDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONObject的用法示例。


在下文中一共展示了JSONObject.putDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: run

        public void run() {
            try {
                // Login
                string token = Query.login("[email protected]", "demobiz");
                Query query = new Query(token);

                // 3. Returns all Assets with no geocode
                JSONObject where = new JSONObject();
                where.put("geo", "");
                JSONObject[] assets = query.select("Assets.assets", where);
                foreach (JSONObject obj in assets) {
                    Console.WriteLine(obj.ToString());
                }

                // Update the first asset with a geo location
                JSONObject firstAsset = (assets.Length > 0) ? assets[0] : null;
                if (firstAsset != null) {
                    JSONObject asset = new JSONObject();
                    asset.put("geo", "51.522020,-0.122198");
                    query.updateId("assets.assets", firstAsset.getString("id"), asset);
                }

                // Insert a new Asset
                JSONObject newAsset = new JSONObject();
                newAsset.put("id", "69794");
                newAsset.put("name", "My Assset");
                newAsset.put("model", "Fiat");
                newAsset.put("geo", "48.858238, 2.347918");
                newAsset.put("serialnumber", "69493949658TYH");
                newAsset.putDate("purchasedate", DateTime.Now);
                newAsset.put("purchaseprice", 12.4f);
                newAsset.put("manufacturer", "Foxconn");
                newAsset.put("geo", "48.858238,2.347918");
                query.insert("assets.assets", newAsset);

            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:39,代码来源:AssetSample.cs

示例2: run

        public void run() {
            try {
                // Login
                string token = Query.login("[email protected]", "demobiz");
                Console.WriteLine("Login OK");

                // Create an instance of hte query class
                Query query = new Query(token);

                // Select all open tasks from the "Tasks.tasks" table 
                // You can go to your Upvise web account in the Task app and create some tasks first
                JSONObject where = new JSONObject();
                where.put("status", 0);
                JSONObject[] tasks = query.select("Tasks.tasks", where);
                Console.WriteLine("Found " + tasks.Length + " open tasks in this database");
                foreach (JSONObject task in tasks) {
                    Console.WriteLine("Task ID: " + task.getString("id"));
                    Console.WriteLine("Name: " + task.getString("name"));
                    Console.WriteLine("Due Date: " + task.getDate("duedate"));
                    Console.WriteLine("Owner: " + task.getString("owner"));
                    Console.WriteLine("Status:" + task.getInt("status"));
                }

                // Create a bunch of tasks using Batch operation
                Console.WriteLine("Creating 10 new tasks...");
                query.beginBatch();
                for (int i = 0; i < 10; i ++) {
                    JSONObject task = new JSONObject();
                    task.put("id", "TASKID_" + i);
                    task.put("name", "My Task " + i);
                    task.put("owner", "John");
                    task.put("status", 0);
                    task.putDate("duedate", DateTime.Now.AddDays(2));

                    query.insert("Tasks.tasks", task);
                }
                query.commitBatch();
                
                // update All open John's Tasks and mark them complete (status=1)
                where.put("owner", "John");
                where.put("status", 0);
                JSONObject[] myTasks = query.select("Tasks.tasks", where);
                Console.WriteLine("found " + myTasks.Length  + " open tasks for John");
                // Start a new batch operation to group all updates into one HTTPS request for best performance
                query.beginBatch();
                foreach(JSONObject task in myTasks) {
                    string id = task.getString("id");
                    JSONObject values = new JSONObject();
                    values.putDate("duedate", DateTime.Now);
                    values.put("status", 1);
                    query.updateId("Tasks.tasks", id, values);
                }
                query.commitBatch();
                Console.WriteLine("Updated the tasks to Complete");

                // Now Get All John's completed Tasks, export them in a file and delete them
                where.put("owner", "John");
                where.put("status", 1);
                JSONObject[] completedTasks = query.select("Tasks.tasks", where);
                Console.WriteLine("found " + completedTasks.Length + " completed tasks for John");

                StringBuilder buffer = new StringBuilder();
                // Start a new batch operation
                query.beginBatch();
                foreach (JSONObject task in completedTasks) {
                    string id = task.getString("id");
                    // Add the task data in the buffer
                    buffer.AppendLine(task.ToString());
                    query.deleteId("Tasks.tasks", id);

                }
                query.commitBatch();
                Console.WriteLine("Deleted completed tasks for John");
                // Save the file to disk
                System.IO.File.WriteAllText(@"C:\\temp\completedTasks.txt", buffer.ToString());
                
            } catch (Exception e) {
                Console.WriteLine("Error:" + e.Message);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:80,代码来源:TaskSample.cs


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