c# - 如何将项目附加到退出的 json 数组?下面是我的 json 数组
问题描述
var jsonObject={"data":[{"Id":293,"SourceURL":"//jhthf/hsf/d$","TargetURL":"makemytriip.com","Status":"Failed","UserFriendlyName":"progress","MonthName":"November","StartYear":2020},
{"Id":296,"SourceURL":"//jhthf/hsf/f$","TargetURL":"usermobileapp.com","Status":"Success","UserFriendlyName":"progress","MonthName":"November","StartYear":2020}]}
如何再添加一个参数“entityType”:“Value”,它是该数组中每个项目的对应值?尝试使用 Newtonsoft json( JObject -Add 方法),但它给出以下错误
'对象序列化为数组。需要 JObject 实例。
JObject jo = JObject.FromObject(jsonObject);
jo.Add("SiteOwnerDisplayNames", userDisplayNames);
解决方案
错误在 FromObject 上?FromObject 期望在 JObject 中传递。
尝试使用 Json.Parse 将数组转换为 JObject。
JObject jo = JObject.FromObject(Json.Parse(jsonObject));
您拥有的 jsonObject 是使用数组语法创建的,而不是正确创建的 JObject[]
推荐阅读
- r - 如何在多个ID上循环r中的xirr函数
- reactjs - 按钮单击导致组件输出错误
- azure-cosmosdb - 如何在 azure cosmos db 中为 asp.net core web api 实现上一个/下一个分页
- python - Python 中 set() 中的“添加”操作或 dict() 中的“插入”实际上是 O(n),其中 n 是键字符串的长度?
- sql - 如何使用聚合函数改善慢速 sql 查询
- yocto - 无法执行 do_install_append
- optimization - 使用 AMSGrad 的 ADAM 优化器的异常行为
- excel - 如何在 Excel 中优化 VBA 代码中的多个循环
- c++ - 数组作为函数的参数
- python - 使用 OpenNMT 进行迁移学习