json.net

How to reference external files with JSON.net?

泄露秘密 提交于 2019-12-06 07:17:31
Here is the error I am getting when JSON.net is trying to read my JSON schema ( return JsonSchema.Read(new JsonTextReader(reader)); ): 2014-07-15 15:33:42.7011 [Fatal] Newtonsoft.Json.JsonException: Could not resolve schema reference 'data-result.json'. at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 139 at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src

Coded UI Test now gets error about Newtonsoft.json not being found

白昼怎懂夜的黑 提交于 2019-12-06 06:48:27
I have a simple Coded UI test to log into an application. The test is data driven and uses data from TFS. We are using a TfsTestAgent user (that has admin privileges) that is on both the server and the agent systems. When I execute the test, I see the following error: The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.Error details: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0,

Is there an alternative for ShouldSerialize[PropertyName] in C#?

删除回忆录丶 提交于 2019-12-06 06:21:16
I have been writing a lot of code lately which involves serialization using Json.NET and due to the nature of the data that I serialize, sometimes not all of their properties need to be serialized so, I do as follows... public int Foo { get; set; } public bool ShouldSerializeFoo() => Foo > -1; This's good and works but involves a lot of work if you have many properties ( in my case I have over 100 ). So, I wanted to know if there's an alternative to writing those methods. One alternative option is to specific a [DefaultValue(...)] and use the DefaultValueHandling.Ignore feature: [DefaultValue(

How to deserialize a JSON array with nested arrays of objects

你离开我真会死。 提交于 2019-12-06 06:11:52
I have a JSON string as follows and want to deserialize it: [[{"campaignId":201410018,"programCode":"54321"}],[{"campaignId":201410018,"programCode":"54321"}]] I have created some classes as follows: public class Rootclass { public List<JSONResponse> rootClass { get; set; } } public class JSONResponse { public int campaignId { get; set; } public string programCode { get; set; } } I am calling this JSON.NET method to deserialize the JSON: List<Rootclass> myDeserializedObjList = (List<Rootclass>)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(List<Rootclass>)); But I am getting the

How to send Json Data from Aspx page

心不动则不痛 提交于 2019-12-06 06:02:00
I tried to use TokenInput Jquery for multiple value autocomplete where it requires the JSON response as input data http://loopj.com/jquery-tokeninput/ I am using ASPX page as source <script type="text/javascript" > $(document).ready(function() { $("#txtTest").tokenInput("Complete.aspx", { theme: "facebook" }); }); </script> Edited From Here Question: How to provide the JSON data from a aspx page in the desired format as i have datatable with values according to Querystring from Complete.aspx protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["q

Using JObject and JProperty with JSON.Net 4.0

萝らか妹 提交于 2019-12-06 05:33:02
问题 I'm trying to deserialize JSON in this format: { "data": [ { "installed": 1, "user_likes": 1, "user_education_history": 1, "friends_education_history": 1, "bookmarked": 1 } ] } to a simple string array like this: { "installed", "user_likes", "user_education_history", "friends_education_history", "bookmarked" } using JSON.NET 4.0 I've gotten it to work using the `CustomCreationConverter' public class ListConverter : CustomCreationConverter<List<string>> { public override List<string> Create

How do I Serialize object to json using json.net which contains an image property

烂漫一生 提交于 2019-12-06 05:28:42
问题 I have an object with a number of public properties where one is of type image. I am trying to serialise this using json.net and assume that I will need to base64 encode this and serialise the resultant string. I have tried with the BinaryConverter against the property without success below public class Person { public string name { get; set; } public int age { get; set; } [JsonConverter(typeof(BinaryConverter))] public Image photo { get; set; } public string ToJson() { return JsonConvert

How to parse a TimeSpan value in Newtonsoft JSON

微笑、不失礼 提交于 2019-12-06 05:19:27
问题 I'd like parse JSON string and use the token.Type property to detect values of type JTokenType.TimeSpan . I can't work out how to express the TimeSpan in my input string, everything seems to be interpreted as JTokenType.String. var timeSpanString = TimeSpan.FromHours(1).ToString(); testString = string.Format(@"{{""Value"": ""{0}"" }}", timeSpanString); var statObject = JObject.Parse(testString); JToken token = statObject["Value"]; var tokenValue = token.ToString(); var tokenType = token.Type;

POST JSON with Flurl

半世苍凉 提交于 2019-12-06 05:19:25
I start with Flurl and I would like to create a POST but I think I have a problem with the format of my JSON parameters. You can see the JSON parameters: { "aaaUser" : { "attributes" : { "name" : "device:domain\\login", "pwd" : "123456" } } } These settings work with Postman and now I would like to use Flurl to continue my little POST :) But my JSON format is not correct. using System.Threading.Tasks; using Flurl.Http; namespace Script { class Program { static async Task Main(string[] args) { var result = await "https://IP/api/aaaLogin.json".PostUrlEncodedAsync(new { name = "device:domain\

How to get ReadJson to return “default” behavior - as if CanConvert returned false

我怕爱的太早我们不能终老 提交于 2019-12-06 05:03:57
I have created an implementation of JsonConverter CanConvert always returns true. In ReadJson I want to sometimes just use the "default" behavior, as if CanConvert had returned false and my ReadJson was never called. Various other posts have suggested I do some variation of the following: existingValue = existingValue ?? serializer .ContractResolver .ResolveContract(objectType) .DefaultCreator(); serializer.Populate(reader, existingValue); However, this throws NullReferenceException on .DefaultCreator() . existingValue is always null The ContractResolver that is returned from the serializer is