草庐IT

json_response

全部标签

c# - 我怎样才能用最小起订量模拟 Response.StatusCode?

我有以下方法:publicvoidSetHttpStatusCode(HttpStatusCodehttpStatusCode){Response.StatusCode=(int)httpStatusCode;}以及以下测试:[TestMethod]publicvoidSetHttpStatusCode_SetsCorrectStatusCode(){//Arrange//AnyurlwillsufficevarmockHttpContext=TestHelpers.MakeHttpContext("");mockHttpContext.SetupSet(x=>x.Response.S

c# - 使用 JSON.Net 解析 ISO 持续时间

我在Global.asax.cs中有一个具有以下设置的WebAPI项目:varserializerSettings=newJsonSerializerSettings{DateFormatHandling=DateFormatHandling.IsoDateFormat,DateTimeZoneHandling=DateTimeZoneHandling.Utc};serializerSettings.Converters.Add(newIsoDateTimeConverter());varjsonFormatter=newJsonMediaTypeFormatter{Serialize

c# - 将 System.Json 用于非 Silverlight 项目?

知道怎么做吗?如果不可能,什么是适用于C#的良好JSON库? 最佳答案 System.Json现在可通过NuGet在非Silverlight项目中使用(.Net的包管理系统)并有望作为vnext核心框架的一部分发布。NuGet包名为JsonValue.假设我们在字符串变量json中有以下JSON:[{"a":"foo","b":"bar"},{"a":"anotherfoo","b":"anotherbar"}]我们可以使用以下代码将值“anotherbar”写入控制台:usingSystem.Json;dynamicjsonObj

C# 序列化字典 <ulong,ulong> 到 JSON

我正在尝试将字典序列化为JSON,并出现以下异常:newJavaScriptSerializer().Serialize(mydict)`Type'System.Collections.Generic.Dictionary`2[[System.UInt64,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.UInt64,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77

c# - RestSharp JSON 数组反序列化

我以JSON格式启动此RestSharp查询:varresponse=restClient.Execute(request);我得到的响应包含这些数据[{"Columns":[{"Name":"CameraGuid","Type":"Guid"},{"Name":"ArchiveSourceGuid","Type":"Guid"},{"Name":"StartTime","Type":"DateTime"},{"Name":"EndTime","Type":"DateTime"},{"Name":"TimeZone","Type":"String"},{"Name":"Capabili

c# - 序列化有时是数组的 Json 属性

这个问题在这里已经有了答案:HowtohandlebothasingleitemandanarrayforthesamepropertyusingJSON.net(9个回答)关闭7年前。有没有办法在一次操作中序列化一个从小数到小数[]的Json对象属性?在我的Json产品提要中,特价商品表示为一个数组(正常价格/促销价)。普通商品只是价格。像这样:[{"product":"umbrella","price":10.50,},"product":"chainsaw","price":[39.99,20.0]}]让它工作的唯一方法是将属性设为对象,如下所示:publicclassProdu

c# - .net 核心 'Response.Cookies.Append' 不作为某个站工作

我正在按照ASP.NETCore2.1文档(https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#implement-a-strategy-to-select-the-languageculture-for-each-request)中的建议使用“Response.Cookies.Append”来设置文化。它在我的工作站上运行得非常好。但是当我的同事获取我的更改时,它不起作用。在调试过程中,我发现“Response.Cookies.Append”没有添加co

c# - 使用@Json.Encode 时隐藏模型中的字段

在我的ASP.NETMVC4应用程序中,我有这样定义的模型:publicclassEmployee:BaseObject{[JsonIgnore]publicstringFirstName{get;set;}[JsonIgnore]publicstringLastName{get;set;}[JsonIgnore]publicstringManager{get;set;}publicstringLogin{get;set;}...}当我使用ApiController返回此对象时,我得到正确的对象without字段具有JsonIgnore属性,但是当我尝试使用以下代码在cshtml文件中

c# - Json 字符串在 web-api 中被转义

我们将JSON配置数据存储在数据库中。我需要获取此JSON数据并将其按原样通过asp.netweb-api返回给浏览器:publicclassConfigurationController:ApiController{publicstringGet(stringconfigId){//Getjsonfromdatabase//whenireturnthefetchedjsonitget'sescaped}}我返回的值被转义了。我如何简单地按原样返回字符串?我真的不想填充一个序列化为JSON的对象。 最佳答案 您可以从ApiContr

c# - 在 Json.NET 序列化中忽略基类属性

我有以下类结构:[JsonObject]publicclassPolygon:IEnumerable{publicListVertices{get;set;}publicAxisAlignedRectangleEnvelope{get;set;}}publicclassAxisAlignedRectangle:Polygon{publicdoubleLeft{get;set;}...}我正在序列化Polygon类,但是当我这样做时,我得到一个JsonSerializationException,以及消息Selfreferencingloopdetectedforproperty'Env