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


C# JObject.Add方法代码示例

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


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

示例1: FormatPropertyInJson

        public void FormatPropertyInJson()
        {
            JObject query = new JObject();
            JProperty orderProp = new JProperty("order", "breadth_first");
            query.Add(orderProp);

            JObject returnFilter = new JObject();
            returnFilter.Add("body", new JValue("position.endNode().getProperty('name').toLowerCase().contains('t')"));
            returnFilter.Add("language", new JValue("javascript"));

            query.Add("return_filter", new JValue(returnFilter.ToString()));

            JObject pruneEval = new JObject();
            pruneEval.Add("body", new JValue("position.length() > 10"));
            pruneEval.Add("language", new JValue("javascript"));
            query.Add("prune_evaluator", pruneEval.ToString());

            query.Add("uniqueness", new JValue("node_global"));

            JArray relationships = new JArray();
            JObject relationShip1 = new JObject();
            relationShip1.Add("direction", new JValue("all"));
            relationShip1.Add("type", new JValue("knows"));
            relationships.Add(relationShip1);

            JObject relationShip2 = new JObject();
            relationShip2.Add("direction", new JValue("all"));
            relationShip2.Add("type", new JValue("loves"));
            relationships.Add(relationShip2);

            query.Add("relationships", relationships.ToString());
            //arr.Add(
            Console.WriteLine(query.ToString());
            //Assert.AreEqual(@"""order"" : ""breadth_first""", jobject.ToString());
        }
开发者ID:sonyarouje,项目名称:Neo4jD,代码行数:35,代码来源:DataFormatTest.cs

示例2: ToJSON

        public static JObject ToJSON(this QueryResult myQueryResult)
        {
            // root element...
            var _Query = new JObject();

            // query --------------------------------
            _Query.Add(new JProperty("query", myQueryResult.Query));

            // result -------------------------------
            _Query.Add(new JProperty("result", myQueryResult.ResultType.ToString()));

            // duration -----------------------------
            _Query.Add(new JProperty("duration", new JArray(myQueryResult.Duration, "ms")));

            // warnings -----------------------------
            _Query.Add(new JProperty("warnings", new JArray(
                from _Warning in myQueryResult.Warnings
                select new JObject(
                         new JProperty("code", _Warning.GetType().ToString()),
                         new JProperty("description", _Warning.ToString())
                       ))));

            // errors -------------------------------
            _Query.Add(new JProperty("errors", new JArray(
                from _Error in myQueryResult.Errors
                select new JObject(
                         new JProperty("code", _Error.GetType().ToString()),
                         new JProperty("description", _Error.ToString())
                       ))));

            // results ------------------------------
            _Query.Add(new JProperty("results", new JArray(GetJObjectsFromResult(myQueryResult.Vertices))));

            return _Query;
        }
开发者ID:ipbi,项目名称:sones,代码行数:35,代码来源:JSON_IO_Extensions.cs

示例3: GetTestRestQuery

        private string GetTestRestQuery()
        {
            JObject query = new JObject();
            JProperty orderProp = new JProperty("order", "breadth_first");
            query.Add(orderProp);

            JObject returnFilter = new JObject();
            returnFilter.Add("body", new JValue("position.endNode().getProperty('FirstName').toLowerCase().contains('sony')"));
            returnFilter.Add("language", new JValue("javascript"));
            JProperty filter = new JProperty("return_filter", returnFilter);
            query.Add(filter);

            JArray relationships = new JArray();
            JObject relationShip1 = new JObject();
            relationShip1.Add("direction", new JValue("out"));
            relationShip1.Add("type", new JValue("wife"));
            relationships.Add(relationShip1);

            JObject relationShip2 = new JObject();
            relationShip2.Add("direction", new JValue("all"));
            relationShip2.Add("type", new JValue("loves"));
            relationships.Add(relationShip2);
            JProperty relationShipProp = new JProperty("relationships", relationships);

            query.Add(relationShipProp);

            JProperty uniqueness = new JProperty("uniqueness", "node_global");
            query.Add(uniqueness);
            JProperty maxDepth = new JProperty("max_depth", 2);
            query.Add(maxDepth);
            return query.ToString();
        }
开发者ID:sonyarouje,项目名称:Neo4jD,代码行数:32,代码来源:RESTApi_Test.cs

示例4: Import

        public ActionResult Import(string savedFileName)
        {
            var jo = new JObject();
            string result;

            try
            {
                var fileName = string.Concat(Server.MapPath(fileSavedPath), "/", savedFileName);

                var importZipCodes = new List<TaiwanZipCode>();

                var helper = new ImportDataHelper();
                var checkResult = helper.CheckImportData(fileName, importZipCodes);

                jo.Add("Result", checkResult.Success);
                jo.Add("Msg", checkResult.Success ? string.Empty : checkResult.ErrorMessage);

                if (checkResult.Success)
                {
                    //儲存匯入的資料
                    helper.SaveImportData(importZipCodes);
                }
                result = JsonConvert.SerializeObject(jo);
            }
            catch (Exception ex)
            {
                throw;
            }
            return Content(result, "application/json");
        }
开发者ID:hsinchenhuang,项目名称:MVC-Excel-Import-Export,代码行数:30,代码来源:ZipCodeController.cs

示例5: addToApplicationSearch

        public void addToApplicationSearch(Keymap keymap, string search)
        {
            if (this.isInApplicationSearch(keymap))
            {
                return;
            }

            JToken level1 = this.jsonObj.GetValue("Applications");
            if (level1 == null)
            {
                this.jsonObj.Add("Applications", new JArray());
            }
            level1 = this.jsonObj.GetValue("Applications");
            JArray array = (JArray)level1;

            JObject newObj = new JObject();
            newObj.Add("Search", search);
            newObj.Add("Keymap", keymap.Filename);
            array.Add(newObj);

            this.jsonObj.Remove("Applications");
            this.jsonObj.Add("Applications", array);

            save();
        }
开发者ID:marquinio007,项目名称:Touchmote,代码行数:25,代码来源:KeymapSettings.cs

示例6: GetActivePlayers

        public List<ActivePlayer> GetActivePlayers(XbmcSettings settings)
        {
            try
            {
                var postJson = new JObject();
                postJson.Add(new JProperty("jsonrpc", "2.0"));
                postJson.Add(new JProperty("method", "Player.GetActivePlayers"));
                postJson.Add(new JProperty("id", 10));

                var response = _httpProvider.PostCommand(settings.Address, settings.Username, settings.Password, postJson.ToString());

                if (CheckForError(response))
                    return new List<ActivePlayer>();

                var result = Json.Deserialize<ActivePlayersEdenResult>(response);

                return result.Result;
            }

            catch (Exception ex)
            {
                _logger.DebugException(ex.Message, ex);
            }

            return new List<ActivePlayer>();
        }
开发者ID:niel,项目名称:NzbDrone,代码行数:26,代码来源:JsonApiProvider.cs

示例7: Index

        public ActionResult Index(string errorMessage)
        {
            var client = new CouchClient("dannylane.iriscouch.com", 6984, "dannylane", "adminpass", true, AuthenticationType.Cookie);
            var udb = client.GetDatabase("testing");

            JObject jObject = new JObject();

            jObject.Add("DateTime", DateTime.UtcNow);
            jObject.Add("UserHostAddress", Request.UserHostAddress);
            jObject.Add("UserHostName", Request.UserHostName);
          //  jObject.Add("UserLanguages", Request.UserLanguages.ToString());
            
            foreach (var param in Request.QueryString.AllKeys)
            {
                jObject.Add(param, Request.QueryString[param]);
            }

            foreach (var param in Request.Headers.AllKeys)
            {
                jObject.Add(param, Request.Headers[param]);
            }

            var info = new LoveSeat.Document(jObject);
            
            udb.SaveDocument(info);
            return File("favicon.ico","image");
        }
开发者ID:dannylane,项目名称:ErrorBucket.io,代码行数:27,代码来源:LogController.cs

示例8: LoadData

 private void LoadData()
 {
     JObject jo = new JObject();
     jo.Add("BoxMargin", "0");
     jo.Add("BoxFlex", 1);
     UserInfoControl5.Properties = jo.ToString(Formatting.None);
 }
开发者ID:jinwmmail,项目名称:RDFNew,代码行数:7,代码来源:userinfo2.aspx.cs

示例9: Login

        public static async Task<string> Login()
        {

            Console.WriteLine("--- LOGIN ---");
            Console.Write("Username: ");
            string gebruiker = Console.ReadLine();
            Username = gebruiker;

            Console.Write("Password: ");
            string password = Console.ReadLine();

            JObject jsonObj = new JObject();
            jsonObj.Add("gebruiker", gebruiker);
            jsonObj.Add("ww", SHA1Util.SHA1HashStringForUTF8String(password));

            string result = await RequestUtil.Post(LinkBuilder.Build(new string[] { "login" }), jsonObj.ToString());
            string key = String.Empty;


            try
            {
                key = JObject.Parse(result)["SLEUTEL"].ToString();
                Logger.Log("ApiUtil", "Key aqquired: " + key, Logger.LogLevel.Info);
            } catch(Exception e)
            {
                Logger.Log("ApiUtil", result, Logger.LogLevel.Error);
            }
            return key;
        }
开发者ID:RSDT,项目名称:JotiApiT,代码行数:29,代码来源:ApiUtil.cs

示例10: GetDirectory

         /// <summary>
         /// Get the directories and files in the given directory
         /// </summary>
 public async Task<XBMCRPC.Files.GetDirectoryResponse> GetDirectory(string directory=null, XBMCRPC.Files.Media media=0, XBMCRPC.List.Fields.Files properties=null, XBMCRPC.List.Sort sort=null, XBMCRPC.List.Limits limits=null)
 {
     var jArgs = new JObject();
      if (directory != null)
      {
          var jpropdirectory = JToken.FromObject(directory, _client.Serializer);
          jArgs.Add(new JProperty("directory", jpropdirectory));
      }
      if (media != null)
      {
          var jpropmedia = JToken.FromObject(media, _client.Serializer);
          jArgs.Add(new JProperty("media", jpropmedia));
      }
      if (properties != null)
      {
          var jpropproperties = JToken.FromObject(properties, _client.Serializer);
          jArgs.Add(new JProperty("properties", jpropproperties));
      }
      if (sort != null)
      {
          var jpropsort = JToken.FromObject(sort, _client.Serializer);
          jArgs.Add(new JProperty("sort", jpropsort));
      }
      if (limits != null)
      {
          var jproplimits = JToken.FromObject(limits, _client.Serializer);
          jArgs.Add(new JProperty("limits", jproplimits));
      }
     return await _client.GetData<XBMCRPC.Files.GetDirectoryResponse>("Files.GetDirectory", jArgs);
 }
开发者ID:Cocotus,项目名称:Ember-MM-Newscraper,代码行数:33,代码来源:Files.cs

示例11: ConvertRecursively

        private static void ConvertRecursively(IResource currentResource, JObject node, JsonSerializer serializer)
        {
            if (currentResource == null)
            {
                return;
            }

            var currentResourceType = currentResource.GetType();
            var readableProperties = GetReadablePropertyInfos(currentResourceType);

            var nonResourceProperties = readableProperties.Where(IsNeitherResourceOrReservedProperty).ToList();
            var resourceProperties = readableProperties.Where(IsResourceProperty).ToList();

            node.Add(ReservedPropertyNames.Relations, JObject.FromObject(currentResource.Relations, serializer));
            var embeddedResourceObject = new JObject();
            node.Add(ReservedPropertyNames.EmbeddedResources, embeddedResourceObject);

            foreach (var resourceProperty in resourceProperties)
            {                
                var embeddedResourceNodeValue = new JObject();

                ConvertRecursively((IResource)resourceProperty.GetValue(currentResource), embeddedResourceNodeValue, serializer);
                embeddedResourceObject.Add(ToCamelCase(resourceProperty.Name), embeddedResourceNodeValue);
            }

            if (IsCollectionResourceType(currentResourceType))
            {
                var currentResourceDynamic = (dynamic) currentResource;
                var jArray = new JArray();
                string name = "";
                foreach (IResource resourceItem in currentResourceDynamic.Items)
                {
                    var embeddedResourceNodeValue = new JObject();
                    ConvertRecursively(resourceItem, embeddedResourceNodeValue, serializer);
                    jArray.Add(embeddedResourceNodeValue);
                    name =  resourceItem.GetType().Name;
                }

                // Remove the "Resource" by convention.
                if (name.EndsWith("Resource"))
                {
                    name = name.Remove(name.LastIndexOf("Resource", StringComparison.Ordinal));
                }

                embeddedResourceObject.Add(ToCamelCase(name), jArray);
            }

            foreach (var nonResourceProperty in nonResourceProperties)
            {
                var value = nonResourceProperty.GetValue(currentResource);
                if (value != null && value.GetType().GetTypeInfo().IsClass && value.GetType() != typeof(string))
                {
                    node.Add(ToCamelCase(nonResourceProperty.Name), JToken.FromObject(value, serializer));
                }
                else
                {
                    node.Add(ToCamelCase(nonResourceProperty.Name), new JValue(value));
                }                
            }
        }
开发者ID:olohmann,项目名称:Lohmann.HALight,代码行数:60,代码来源:ResourceConverter.cs

示例12: testMsgContentAndExtras

        public void testMsgContentAndExtras()
        {
            Message message = Message.content("msgContent");
            message.AddExtras("key1", "value1");
            message.AddExtras("key2", 222);
            message.AddExtras("key3", false);
            message.Check();

            JObject json = new JObject();
            json.Add("msg_content",JToken.FromObject("msgContent"));

            JObject extras = new JObject();
            extras.Add("key1", JToken.FromObject("value1"));
            extras.Add("key2", JToken.FromObject(222));
            extras.Add("key3", JToken.FromObject(false));

            json.Add("extras", extras);

            var jSetting = new JsonSerializerSettings();
            jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
            var jsonString = JsonConvert.SerializeObject(message, jSetting);
            var jsonObject = json.ToString(Formatting.None);
            var fromJson = JsonConvert.DeserializeObject<Message>(jsonObject);
            Assert.AreEqual(jsonObject, jsonString);
     }
开发者ID:wcgh,项目名称:Zichanguanli-Server-for-C-code,代码行数:25,代码来源:MessageTest.cs

示例13: processer

        public Newtonsoft.Json.Linq.JArray processer(string jsonStr)
        {
            String userID=null;
            String pTypeID=null;
             JArray jsa = JArray.Parse(jsonStr);
            JObject json = JObject.Parse(jsa[0].ToString());
            pTypeID = json["pTypeID"].ToString();
            userID = json["userID"].ToString();
          
		Dict_固定资产Dao dd=new Dict_固定资产Dao();
		
		//例如是3
	List<Model>	list=dd.getAllFatherTypeByID(pTypeID);
	JArray jsaa=new JArray();

	foreach(Model m in list){
		JObject j=new JObject();
		 
			j.Add("代码", ((Dict_固定资产Model)m).get代码());
			j.Add("名称", ((Dict_固定资产Model)m).get名称());
			j.Add("层级码",((Dict_固定资产Model)m).get层级码());
		 
		jsaa.Add(j);
	}
	
		return jsaa;
        }
开发者ID:wcgh,项目名称:Zichanguanli-Server-for-C-code,代码行数:27,代码来源:GetFatherFenleihaoProcesser.cs

示例14: SerializeMessage

        public JObject SerializeMessage(Message message)
        {
            JObject messageObject = new JObject();

            messageObject.Add("jsonrpc", JToken.FromObject("2.0"));

            if (message.MessageType == MessageType.Request)
            {
                messageObject.Add("id", JToken.FromObject(message.Id));
                messageObject.Add("method", message.Method);
                messageObject.Add("params", message.Contents);
            }
            else if (message.MessageType == MessageType.Event)
            {
                messageObject.Add("method", message.Method);
                messageObject.Add("params", message.Contents);
            }
            else if (message.MessageType == MessageType.Response)
            {
                messageObject.Add("id", JToken.FromObject(message.Id));

                if (message.Error != null)
                {
                    // Write error
                    messageObject.Add("error", message.Error);
                }
                else
                {
                    // Write result
                    messageObject.Add("result", message.Contents);
                }
            }

            return messageObject;
        }
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:35,代码来源:JsonRpcMessageSerializer.cs

示例15: Connected

 // 클라이언트가 접속시 호출
 public void Connected(IReceiveContext channel)
 {
     JObject o = new JObject();
     o.Add("name", "test");
     o.Add("value", i++);
     channel.GetChannel().SendMessage(o);
 }
开发者ID:shlee322,项目名称:Netronics,代码行数:8,代码来源:Client.cs


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