Rated 5 Stars (out of 5) - muy bueno por que es muy fácil de usar
↧
Reviewed: Json.NET 6.0 Release 5 (Sep 12, 2014)
↧
New Post: custom type as dictionary key
I have a Dictionary defined like this:
But when I deserialize like so:
Any help would be greatly appreciated.
Dictionary<Time, Mark>
The Time class is defined like this: public class Time
{
public Byte Hour; // 0...23
public Byte Minute; // 0...59
public Time()
{
Hour = (Byte)0;
Minute = (Byte)0;
}
public Time(Byte hour, Byte minute)
{
Hour = (Byte)( ( hour > 23 ) ? 23 : hour );
Minute = (Byte)( ( minute > 59 ) ? 59 : minute );
}
public Time(String stringified)
{
Hour = 0;
Minute = 0;
String[] parts = stringified.Split(':');
if ( parts.Length == 2 )
{
String hour = parts[0];
String minute = parts[1];
if ( ( hour.Length == 2 ) && ( minute.Length == 2 ) )
{
Byte.TryParse(hour, out Hour);
Byte.TryParse(minute, out Minute);
Hour = (Byte)( ( Hour > 23 ) ? 23 : Hour );
Minute = (Byte)( ( Minute > 59 ) ? 59 : Minute );
}
}
}
public override String ToString()
{
return String.Format("{0}{1}:{2}{3}", ((Hour<10)?"0":""), Hour, ((Minute<10)?"0":""), Minute);
}
}
When I serialize like so:String json = JsonConvert.SerializeObject(this, Formatting.Indented);
System.IO.File.WriteAllText("/Users/pgkbb/Desktop/KbB.prefs/Scheduler.json", json);
... i get:"Marks": {
"00:00": 0,
"06:00": 1,
"20:00": 0
}
... which looks good.But when I deserialize like so:
String json = System.IO.File.ReadAllText("/Users/pgkbb/Desktop/KbB.prefs/Scheduler.json");
State state = JsonConvert.DeserializeObject<State>(json);
... an exception is thrown that says:Could not convert string '00:00' to dictionary key type 'MyNamespace.Time'. Create a TypeConverter to convert from the string to the key type object.
I've tried standard .NET TypeConverter subclasses and JsonConverter subclasses and still can't get those string keys to deserialize back into Time objects.Any help would be greatly appreciated.
↧
↧
New Post: JObject could / should(?) ignore null params instead of throwing
I completely agree that it would be great if the Linq to Json component ignored nulls. I also agree that it is awkward to come back in a second pass to add the optional properties if you have anything but the most basic of structures. In my case, I'm building JSON for Google Analytics/Google Tag Manager:
https://support.google.com/tagmanager/answer/3002596
Some of those optional fields may or may not be filled in depending on various factors.
https://support.google.com/tagmanager/answer/3002596
Some of those optional fields may or may not be filled in depending on various factors.
↧
New Post: Deserialiize
I have these json
{
"user": {
}
How do I deserialize it into object class in vb.net?
the issue is the tag is 0, 1, 2 (number) and I don't think we have to define all the number one by one. i tried array and list it doesn't work cause can't use index as property name?
{
"user": {
"id": 100,
"status": "ACTIVE",
"gender": "MALE",
"loyalty": {
"0": {
"loyalty_program": {
"id": 29,
"title": "General Loyalty Program"
},
"join_date": "23-04-2014",
"expiry_date": null
},
"1": {
"loyalty_program": {
"id": 22,
"title": "General Loyalty Program"
},
"join_date": "23-04-2014",
"expiry_date": null
},
"3": {
"loyalty_program": {
"id": 11,
"title": "General Loyalty Program"
},
"join_date": "23-04-2014",
"expiry_date": null,
}
}
}}
How do I deserialize it into object class in vb.net?
the issue is the tag is 0, 1, 2 (number) and I don't think we have to define all the number one by one. i tried array and list it doesn't work cause can't use index as property name?
↧
Created Unassigned: Newtonsoft.Json.PreserveReferencesHandling.None not being applied [25741]
In my Web API config I have the following set:
jsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
But I still get $id/$ref output when serialized. Has anyone seen this before? Is there a solution?
jsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
But I still get $id/$ref output when serialized. Has anyone seen this before? Is there a solution?
↧
↧
New Post: JsonSerialization exception + Unexpected end when deserializing object.
I used Newtonsoft.json dll for json deserialization
Here I will include my jsonstring value that should be deserialized to object
Here I will include my jsonstring value that should be deserialized to object
{"__type":"xPad.Reports.ReportDetail","ReportTitle":"Police Incident","ReportFooter":"","ReportHeader":"","CommonFields":[{"FormFieldTitle":"Actual Date","FormFieldValue":""},{"FormFieldTitle":"Incident Received Date","FormFieldValue":""},{"FormFieldTitle":"Original Activity Code","FormFieldValue":""},{"FormFieldTitle":"Priority Code","FormFieldValue":""},{"FormFieldTitle":"Response Type Code","FormFieldValue":""},{"FormFieldTitle":"Action Taken Code","FormFieldValue":""},{"FormFieldTitle":"Reported IncidentType Value","FormFieldValue":""},{"FormFieldTitle":"Actual End Date","FormFieldValue":""},{"FormFieldTitle":"ORI","FormFieldValue":""},{"FormFieldTitle":"Close Date","FormFieldValue":""},{"FormFieldTitle":"Incident First Arrival Date","FormFieldValue":""},{"FormFieldTitle":"Incident First Dispatch Date","FormFieldValue":""},{"FormFieldTitle":"Incident Last Clear Date","FormFieldValue":""},{"FormFieldTitle":"Police Incident Alternate Reference Number","FormFieldValue":""},{"FormFieldTitle":"Primary City","FormFieldValue":""},{"FormFieldTitle":"Primary Apartment Number","FormFieldValue":""},{"FormFieldTitle":"Primary State Code","FormFieldValue":""},{"FormFieldTitle":"Primary Street Number","FormFieldValue":""},{"FormFieldTitle":"Primary Street Name","FormFieldValue":""},{"FormFieldTitle":"Primary Zip Code","FormFieldValue":""},{"FormFieldTitle":"Incident Summary","FormFieldValue":""},{"FormFieldTitle":"Suffix Name","FormFieldValue":""},{"FormFieldTitle":"Landmark","FormFieldValue":""}],"Sections":[{"SectionTitle":"Business","ShowTitleSection":true,"SubSections":[{"SubSectionTitle":"Business","ShowTitleSubSection":true,"FormGroups":[{"FormGroupTitle":"Business","ShowTitleFormGroup":true,"FormFields":[{"FormFieldTitle":"Business Name","FormFieldValue":""},{"FormFieldTitle":"Business City","FormFieldValue":""},{"FormFieldTitle":"Business Apartment Number","FormFieldValue":""},{"FormFieldTitle":"Business State Code","FormFieldValue":""},{"FormFieldTitle":"Business Street Name","FormFieldValue":""},{"FormFieldTitle":"Business Street Number","FormFieldValue":""},{"FormFieldTitle":"Business ZipCode","FormFieldValue":""},{"FormFieldTitle":"Business Street Suffix","FormFieldValue":""}]}]}]},{"SectionTitle":"Type Assigned","ShowTitleSection":true,"SubSections":[{"SubSectionTitle":"Type Assigned","ShowTitleSubSection":true,"FormGroups":[{"FormGroupTitle":"Type Assigned","ShowTitleFormGroup":true,"FormFields":[{"FormFieldTitle":"Incident Type Value","FormFieldValue":""},{"FormFieldTitle":"Incident Type Primary Indicator","FormFieldValue":""},{"FormFieldTitle":"Incident Type Reported Indicator","FormFieldValue":""}]}]}]},{"SectionTitle":"Person","ShowTitleSection":true
↧
Reviewed: Json.NET 6.0 Release 5 (Sep 26, 2014)
Rated 5 Stars (out of 5) - This will help android developers to synchronize apps data with asp.net websites.
↧
New Post: Serialization depth
So, has anyone been able to do this?
I need to set a max depth on serializing an object. I never plan on deserializing it.
I need to set a max depth on serializing an object. I never plan on deserializing it.
↧
New Post: JsonConvert.DeserializeObject
When i deserialize the object i get null values for fields that are not there in input string, how do i avoid those null properties, my client does not need them...
I tried using NullValueHandling.Ignore and did not work out... googled for 1 day and but no luck...
greatly appreciate the response.. is this possible or not ?
I tried using NullValueHandling.Ignore and did not work out... googled for 1 day and but no luck...
greatly appreciate the response.. is this possible or not ?
↧
↧
New Post: Camel Case for most properties, but not all.
I know this is quite an old thread. But I was wondering if you have ever found a solution.
↧
New Post: Problem when deserializing null values to properties of type JObject
Hi,
I met the exact same problem. I am using version 6.0.5.
Could anybody shed some light on this?
Thanks,
Karl
I met the exact same problem. I am using version 6.0.5.
Could anybody shed some light on this?
Thanks,
Karl
↧
Commented Unassigned: Allow setting of $id property for PreserveReferencesHandling [25698]
We use guids for our EF ids, it would be great to be able to specify that a particular property could be used as the $id property for purposes of PreserveReferencesHandling
Comments: ** Comment from web user: JamesNK **
Comments: ** Comment from web user: JamesNK **
You can. Ask on Stackoverflow.
↧
Closed Unassigned: can I request a feature to ignore the TypeConvertor? [25583]
I have a class , for support a Window Form Designer, I define a custom TypeConvertor:
and also I need to implement a web deisigner, but JsonConvert will call the TypeConvertor to get the string return by the TypeConvertor, it's not what I want.
I googled and found others also meet this issue.
so, can you support to ignore the TypeConvertor?
Comments: If this is a problem I recommend you use a new class when serializing.
and also I need to implement a web deisigner, but JsonConvert will call the TypeConvertor to get the string return by the TypeConvertor, it's not what I want.
I googled and found others also meet this issue.
so, can you support to ignore the TypeConvertor?
Comments: If this is a problem I recommend you use a new class when serializing.
↧
↧
New Post: Convert datamodel.bin to json format...
Good day!
Please help me. How can I convert this bin file in json format. I do not know how but I do know that this is possible. Because the other person did. However, he does not want to say how.
datamodel.bin
Please help me. How can I convert this bin file in json format. I do not know how but I do know that this is possible. Because the other person did. However, he does not want to say how.
datamodel.bin
↧
Created Release: Json.NET 6.0 Release 6 (Oct 24, 2014)
- New feature - Added support for ASP.NET CoreCLR
- New feature - Reduced memory allocations when reading and writing JSON
- New feature - Added support for passing arguments to JsonConverters with JsonConvertAttribute
- New feature - Added JsonConvert.ToString overload that takes a StringEscapeHandling parameter
- Change - Omit fields array for F# discriminated union serialization when there are no fields
- Change - Escape property names in path on readers/writers/tokens when a name contains special characters
- Change - Provide line numbers for end tokens on JTokenReader
- Fix - Fixed parsing SelectToken when the path has an escaped property followed by an unescaped property
- Fix - Fixed error when deserializing a GUID from certain BSON
- Fix - Fixed null reference error when using a JEnumerable created with its default constructor
- Fix - Fixed line breaks in exception messages to use Environment.NewLine
- Fix - Fixed MetadataTypeAttribute reflection error on ASP.NET CoreCLR
- Fix - Fixed immutable collections reflection error on ASP.NET CoreCLR
↧
Released: Json.NET 6.0 Release 6 (Oct 24, 2014)
- New feature - Added support for ASP.NET CoreCLR
- New feature - Reduced memory allocations when reading and writing JSON
- New feature - Added support for passing arguments to JsonConverters with JsonConvertAttribute
- New feature - Added JsonConvert.ToString overload that takes a StringEscapeHandling parameter
- Change - Omit fields array for F# discriminated union serialization when there are no fields
- Change - Escape property names in path on readers/writers/tokens when a name contains special characters
- Change - Provide line numbers for end tokens on JTokenReader
- Fix - Fixed parsing in SelectToken when the path has an escaped property followed by an unescaped property
- Fix - Fixed error when deserializing a GUID from certain BSON
- Fix - Fixed null reference error when using a JEnumerable created with its default constructor
- Fix - Fixed line breaks in exception messages to use Environment.NewLine
- Fix - Fixed MetadataTypeAttribute reflection error on ASP.NET CoreCLR
- Fix - Fixed immutable collections reflection error on ASP.NET CoreCLR
↧
Updated Release: Json.NET 6.0 Release 6 (Oct 24, 2014)
- New feature - Added support for ASP.NET CoreCLR
- New feature - Reduced memory allocations when reading and writing JSON
- New feature - Added support for passing arguments to JsonConverters with JsonConvertAttribute
- New feature - Added JsonConvert.ToString overload that takes a StringEscapeHandling parameter
- Change - Omit fields array for F# discriminated union serialization when there are no fields
- Change - Escape property names in path on readers/writers/tokens when a name contains special characters
- Change - Provide line numbers for end tokens on JTokenReader
- Fix - Fixed parsing in SelectToken when the path has an escaped property followed by an unescaped property
- Fix - Fixed error when deserializing a GUID from certain BSON
- Fix - Fixed null reference error when using a JEnumerable created with its default constructor
- Fix - Fixed line breaks in exception messages to use Environment.NewLine
- Fix - Fixed MetadataTypeAttribute reflection error on ASP.NET CoreCLR
- Fix - Fixed immutable collections reflection error on ASP.NET CoreCLR
↧
↧
Reviewed: Json.NET 6.0 Release 6 (out 29, 2014)
Rated 5 Stars (out of 5) - Excellent API! I'm deserializing hundreds of packages in question of seconds!!
↧
Created Unassigned: Json.NET not thread safe? [25809]
We are facing the following exception during Serialize(...)
Is JsonSerializer thread safe or is it really required to create a instance per thread?
Newtonsoft.Json.JsonSerializationException: Error writing object reference for 'MyWrapper'. Path 'mIdentityWrapper'. ---> System.ArgumentException: A different value already has the Id '294823'.
at Newtonsoft.Json.Utilities.BidirectionalDictionary`2.Set(TFirst first, TSecond second)
at Newtonsoft.Json.Serialization.DefaultReferenceResolver.GetReference(Object context, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteReferenceIdProperty(JsonWriter writer, Type type, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Looks like that resolving of the corresponding types lead to adding stuff twice in BidirectionalDictionary. This error is reported through the HandleJsonError Event.
Besides of that also the exception handling has a issue because we also retrieve the following exception
System.InvalidOperationException: Current error context error is different to requested error.
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.GetErrorContext(Object currentObject, Object member, String path, Exception error)
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.IsErrorHandled(Object currentObject, JsonContract contract, Object keyValue, IJsonLineInfo lineInfo, String path, Exception ex)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
Is JsonSerializer thread safe or is it really required to create a instance per thread?
Newtonsoft.Json.JsonSerializationException: Error writing object reference for 'MyWrapper'. Path 'mIdentityWrapper'. ---> System.ArgumentException: A different value already has the Id '294823'.
at Newtonsoft.Json.Utilities.BidirectionalDictionary`2.Set(TFirst first, TSecond second)
at Newtonsoft.Json.Serialization.DefaultReferenceResolver.GetReference(Object context, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteReferenceIdProperty(JsonWriter writer, Type type, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Looks like that resolving of the corresponding types lead to adding stuff twice in BidirectionalDictionary. This error is reported through the HandleJsonError Event.
Besides of that also the exception handling has a issue because we also retrieve the following exception
System.InvalidOperationException: Current error context error is different to requested error.
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.GetErrorContext(Object currentObject, Object member, String path, Exception error)
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.IsErrorHandled(Object currentObject, JsonContract contract, Object keyValue, IJsonLineInfo lineInfo, String path, Exception ex)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
↧
Closed Unassigned: Json.NET not thread safe? [25809]
We are facing the following exception during Serialize(...)
Is JsonSerializer thread safe or is it really required to create a instance per thread?
Newtonsoft.Json.JsonSerializationException: Error writing object reference for 'MyWrapper'. Path 'mIdentityWrapper'. ---> System.ArgumentException: A different value already has the Id '294823'.
at Newtonsoft.Json.Utilities.BidirectionalDictionary`2.Set(TFirst first, TSecond second)
at Newtonsoft.Json.Serialization.DefaultReferenceResolver.GetReference(Object context, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteReferenceIdProperty(JsonWriter writer, Type type, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Looks like that resolving of the corresponding types lead to adding stuff twice in BidirectionalDictionary. This error is reported through the HandleJsonError Event.
Besides of that also the exception handling has a issue because we also retrieve the following exception
System.InvalidOperationException: Current error context error is different to requested error.
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.GetErrorContext(Object currentObject, Object member, String path, Exception error)
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.IsErrorHandled(Object currentObject, JsonContract contract, Object keyValue, IJsonLineInfo lineInfo, String path, Exception ex)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
Comments: DefaultReferenceResolver isn't thread safe.
Is JsonSerializer thread safe or is it really required to create a instance per thread?
Newtonsoft.Json.JsonSerializationException: Error writing object reference for 'MyWrapper'. Path 'mIdentityWrapper'. ---> System.ArgumentException: A different value already has the Id '294823'.
at Newtonsoft.Json.Utilities.BidirectionalDictionary`2.Set(TFirst first, TSecond second)
at Newtonsoft.Json.Serialization.DefaultReferenceResolver.GetReference(Object context, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetReference(JsonWriter writer, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteReferenceIdProperty(JsonWriter writer, Type type, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
Looks like that resolving of the corresponding types lead to adding stuff twice in BidirectionalDictionary. This error is reported through the HandleJsonError Event.
Besides of that also the exception handling has a issue because we also retrieve the following exception
System.InvalidOperationException: Current error context error is different to requested error.
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.GetErrorContext(Object currentObject, Object member, String path, Exception error)
at Newtonsoft.Json.Serialization.JsonSerializerInternalBase.IsErrorHandled(Object currentObject, JsonContract contract, Object keyValue, IJsonLineInfo lineInfo, String path, Exception ex)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
Comments: DefaultReferenceResolver isn't thread safe.
↧