草庐IT

JSON_ENCODE

全部标签

c# - 使用 Json.Net C# 获取 json 对象中的值和键

你好,我有一个看起来像这样的json:{"Id":"357342524563456678","title":"Person","language":"eng","questionAnswer":[{"4534538254745646.1":{"firstName":"Janet","questionNumber":"1.1"}}]}现在我已经编写了一些代码来遍历questionAnswer数组中的对象,然后获取对象的名称,即4534538254745646.1。现在我试图保存每个项目的键和值,但我只能设法获取值。我该怎么做,这是我的代码:JTokenentireJson=JToken.

c# - 使用 Json.NET 使用新的部分 JSON 数据修改现有对象

考虑下面的示例程序varcalendar=newCalendar{Id=42,CoffeeProvider="Espresso2000",Meetings=new[]{newMeeting{Location="Room1",From=DateTimeOffset.Parse("2014-01-01T00:00:00Z"),To=DateTimeOffset.Parse("2014-01-01T01:00:00Z")},newMeeting{Location="Room2",From=DateTimeOffset.Parse("2014-01-01T02:00:00Z"),To=Date

c# - 如何强制 WebAPI 使用 JSON.net 6.0.3 而不是 4.5?

添加WebAPI并在Global.asax中注册后。我们发现我们的网络应用程序在这一行中断:Line17:GlobalConfiguration.Configure(WebApiConfig.Register);错误信息:Couldnotloadfileorassembly'Newtonsoft.Json,Version=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed'oroneofitsdependencies.Thesystemcannotfindthefilespecified.经过一些检查,我发现我们在这个MVC5

c# - 将 .Net 对象序列化为 json,使用 xml 属性控制

我有一个.Net对象,我一直在将其序列化为Xml,并使用Xml属性进行装饰。我现在想将同一个对象序列化为Json,最好使用NewtonsoftJson.Net图书馆。我想直接从内存中的.Net对象转到Json字符串(无需先序列化为Xml)。我不希望向该类添加任何Json属性,而是希望Json序列化程序使用现有的Xml属性。publicclassworld{[XmlIgnore]publicintignoreMe{get;}[XmlElement("foo")]publicintbar{get;}[XmlElement("marco")]publicintpolo{get;}}成为{"f

c# - 如何在 json.net 中将空字符串反序列化为枚举

我正在将json属性反序列化为一个枚举,但是当属性为空字符串时,我在处理情况时遇到了问题。Errorconvertingvalue""totype'EnrollmentState'我正在尝试反序列化requiredItem中的state属性。{"currentStage":"Pre-Approved","stages":["Applicant","Pre-Approved","Approved","Enrolled"],"requiredItems":[{"id":1,"name":"Documents","state":""},{"id":2,"name":"EligibilityV

c# - 在 json 和 Web api 之间保持 C# datetime 本地时间?

当我在json对象中有数据时间时遇到问题,它将在C#dateTime中将其转换为UTC时区只是想问一下如何保持本地时间?我可以在web.config文件或geter或setter中设置时区属性,因为我必须反对有日期和时间吗?这是类示例?publicclassPatient{publiclongRecordId{get;set;}publicstringUsername{get;set;}publicDateTimeDate{get;set;}publicboolDeleted{get;set;}publicstringModifiedBy{get;set;}publicDateTime

c# - 反序列化具有以数字开头的某些属性名称的json

JSON数据看起来像这样[{"market_id":"21","coin":"DarkCoin","code":"DRK","exchange":"BTC","last_price":"0.01777975","yesterday_price":"0.01770278","change":"+0.43","24hhigh":"0.01800280","24hlow":"0.01752015","24hvol":"404.202","top_bid":"0.01777975","top_ask":"0.01790000"}]注意这里的这3个属性24high、24hhlow和24hvol您

c# - 使用 Json.Net 反序列化时出现错误 "Cannot deserialize the current JSON array"

我有一个字符串:[{"key":"key1","value":"{'Time':'15:18:42','Data':'15:18:42'}","duration":5},{"key":"key1","value":"{'Time':'15:18:42','Data':'15:18:42'}","duration":5}]我的模型类:publicclassCPacket{publicstringkey{get;set;}publicstringvalue{get;set;}publicintduration{get;set;}}我使用Json.Net,我想将下面的字符串转换为Json对象

c# - 使用 appsettings.json 配置 Serilog RollingFile

我正在尝试为.NETCore项目配置Serilog。这是我的appsettings.json中的内容:"Serilog":{"MinimumLevel":"Verbose","Enrich":["FromLogContext","WithMachineName","WithProcessId","WithThreadId"],"WriteTo":[{"Name":"RollingFile","Args":{"pathFormat":"C:/Logfiles/testapp/log-{Date}.json","textFormatter":"JsonFormatter","fileSiz

c# - 使用 JSON.NET 序列化对象的动态属性名称

我使用JSON.NET序列化我的对象以连接到RESTAPI。我的对象中需要序列化为JSON的属性之一具有动态属性名称。如果此属性的结构中包含的值为数值,则JSON属性为“type_id”,但如果此值为字符串值,则JSON属性名称为“type_code”。我尝试为此使用自定义JsonConverter,但是当我尝试序列化时,我得到了一个带有此消息的JsonWriterException:"TokenPropertyNameinstatePropertywouldresultinaninvalidJSONobject.Path''."下面是我的对象的一个​​子集,如下所示,我没有在我的对象