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());
}
示例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;
}
示例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();
}
示例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");
}
示例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();
}
示例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>();
}
示例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");
}
示例8: LoadData
private void LoadData()
{
JObject jo = new JObject();
jo.Add("BoxMargin", "0");
jo.Add("BoxFlex", 1);
UserInfoControl5.Properties = jo.ToString(Formatting.None);
}
示例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;
}
示例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);
}
示例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));
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例15: Connected
// 클라이언트가 접속시 호출
public void Connected(IReceiveContext channel)
{
JObject o = new JObject();
o.Add("name", "test");
o.Add("value", i++);
channel.GetChannel().SendMessage(o);
}
C# JObject.Add方法代码示例的更多相关文章
- axios get及post方法代码示例&&方法封装
axios get及post方法代码示例 get方法: show: function(){ //get方式 //赋值给变量self var self = this; var url = "h ...
- MFC编辑框接收数据动态更新与刷新方法代码示例-如何让编辑框内容实时更新
MFC编辑框接收数据动态更新与刷新方法代码示例-如何让编辑框内容实时更新 关键代码: //发送数据通知 //from txwtech@163.com LRESULT CCommSampleDlg::O ...
- [deviceone开发]-动态添加组件add方法的示例
一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...
- ref:关于JAVA中一些安全漏洞示例说明及如何规避方法代码示例总结分享
ref:http://www.xwood.net/_site_domain_/_root/5870/5874/t_c268166.html 标签:安全,漏洞,健壮,java,SQL注入,SS及CSRF ...
- php发送get、post请求的6种方法代码示例
本文主要展示了php发送get.post请求的6种方法的代码示例,分别为使用file_get_contents .fopen.fsockopen.curl来发送GET和POST请求,代码如下: 方法1 ...
- SQL注入原理与解决方法代码示例
一.什么是sql注入? 1.什么是sql注入呢? 所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令,比如先前的很多影视网 ...
- 25个JavaScript数组方法代码示例
摘要: 通过代码掌握数组方法. 原文:通过实现25个数组方法来理解及高效使用数组方法(长文,建议收藏) 译者:前端小智 Fundebug经授权转载,版权归原作者所有. 要在给定数组上使用方法,只需要通 ...
- php一些单选、复选框的默认选择方法(示例)
转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...
- 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好
HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...
- laravel 框架配置404等异常页面的方法详解(代码示例)
本篇文章给大家带来的内容是关于laravel 框架配置404等异常页面的方法详解(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 在Laravel中所有的异常都由Handl ...
随机推荐
- JavaScript 高阶技巧
0x01 深浅拷贝 开发中经常需要拷贝(复制)一个对象,如果直接赋值,则对拷贝对象的修改会影响到源对象 const o1 = { a: 1, b: 2 } const o2 = o1 console. ...
- 论文记载:A Survey on Traffic Signal Control Methods
ABSTRACT 交通信号控制是一个重要且具有挑战性的现实问题,其目标是通过协调车辆在道路交叉口的移动来最小化车辆的行驶时间.目前使用的交通信号控制系统仍然严重依赖过于简单的信息和基于规则的方法,尽管 ...
- Pytorch-tensor的激活函数
1.激活函数 激活函数的作用是能够给神经网络加入一些非线性因素,使得神经网络可以更好地解决较为复杂的问题.因为很多问题都不是线性的,你只有给它加入一些非线性因素,就能够让问题更好的解决. 函数1:RE ...
- 使用python获取知乎**话题下的所有回答,并统计后发布。
第一步:获取话题需要的url需要,并向上取整 for idx in range(0,math.ceil(totals/5)): url = f"https://www.zhihu.com/a ...
- vue3.0体验版生命周期
使用方法:cnpm install --save @vue/composition-api在组件内引入 把上图的 onMounted 换成(2.6->3.0) beforeCreate-> ...
- 使用Git向Gitee仓库推送项目的完整流程
1.安装git 如果没有特殊需求,直接下一步即可:安装链接如下:Git - Downloads (git-scm.com) 2.在Gitee上新建仓库,初始化仓库 3.保存仓库的链接,如下图标记所示 ...
- 从 2018 年 Nacos 开源说起
2018 年夏天 国内微服务开源 领域,迎来了一位新成员.此后,在构建微服务注册中心和配置中心的过程中,国内开发者多了一个可信赖的选项. Nacos 是阿里巴巴开源的一个更易于构建云原生应用的动态服务 ...
- PolarDB 并行查询的前世今生
简介:本文会深入介绍PolarDB MySQL在并行查询这一企业级查询加速特性上做的技术探索.形态演进和相关组件的实现原理,所涉及功能随PolarDB MySQL 8.0.2版本上线. 作者 | ...
- PyQt5编程学习之控件基类QObject深入
一.QObject描述: PyQt几乎所有的类都是从QObject直接或间接继承的,QObject是所有PyQt类的基类,是PyQt对象模型的核心. 二.基类QObject的功能: (一)操作对象名称 ...
- [FAQ] 对于 Puppeteer 和 Chromium 在 Linux 上的安装,需要安装哪些依赖库
比如 puppeteer/chrome/linux-114.0.5735.133/chrome-linux64/chrome 到底要装哪些依赖. 一般根据报错提示,安装缺少的即可,以下是一般需要的 ...