Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Pin
Dave Kreskowiak19-Jul-19 9:49
mveDave Kreskowiak19-Jul-19 9:49 
GeneralRe: C# Pin
BillWoodruff20-Jul-19 6:41
professionalBillWoodruff20-Jul-19 6:41 
GeneralRe: C# Pin
Dave Kreskowiak20-Jul-19 13:30
mveDave Kreskowiak20-Jul-19 13:30 
GeneralRe: C# Pin
BillWoodruff20-Jul-19 17:59
professionalBillWoodruff20-Jul-19 17:59 
AnswerRe: C# Pin
ZurdoDev19-Jul-19 10:12
professionalZurdoDev19-Jul-19 10:12 
AnswerRe: how to read data type in excel Pin
Richard MacCutchan19-Jul-19 21:39
mveRichard MacCutchan19-Jul-19 21:39 
AnswerRe: how to read data type in excel Pin
BillWoodruff20-Jul-19 6:44
professionalBillWoodruff20-Jul-19 6:44 
QuestionWCF UnobservedTaskException Pin
Bernhard Hiller19-Jul-19 2:57
Bernhard Hiller19-Jul-19 2:57 
AnswerRe: WCF UnobservedTaskException Pin
Richard Deeming19-Jul-19 3:40
mveRichard Deeming19-Jul-19 3:40 
GeneralRe: WCF UnobservedTaskException Pin
Bernhard Hiller19-Jul-19 4:24
Bernhard Hiller19-Jul-19 4:24 
GeneralRe: WCF UnobservedTaskException Pin
Richard Deeming19-Jul-19 4:41
mveRichard Deeming19-Jul-19 4:41 
GeneralRe: WCF UnobservedTaskException Pin
Bernhard Hiller21-Jul-19 21:00
Bernhard Hiller21-Jul-19 21:00 
Question'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
BillWoodruff18-Jul-19 4:15
professionalBillWoodruff18-Jul-19 4:15 
SuggestionRe: 'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
Richard Deeming18-Jul-19 5:02
mveRichard Deeming18-Jul-19 5:02 
GeneralRe: 'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
BillWoodruff18-Jul-19 5:59
professionalBillWoodruff18-Jul-19 5:59 
GeneralRe: 'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
honey the codewitch20-Jul-19 10:47
mvahoney the codewitch20-Jul-19 10:47 
GeneralRe: 'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
BillWoodruff20-Jul-19 13:34
professionalBillWoodruff20-Jul-19 13:34 
GeneralRe: 'Switch on 'Type: C# 7,8 offer no relief; and, Eric Lippert is still right Pin
honey the codewitch20-Jul-19 13:38
mvahoney the codewitch20-Jul-19 13:38 
QuestionProblem deserialising JSON data [SOLVED by the brilliant Richard Deeming] Pin
Richard MacCutchan18-Jul-19 2:03
mveRichard MacCutchan18-Jul-19 2:03 
I am struggling to deserialize a load of JSON as below (the relevant sections).

The problem is the last array titled volunteer_properties which the DataContractJsonSerializer seems to have a problem with. It appears to me to be an array of anonymous objects, each of which contains a named object which has a number of members. So my DataContract entries are trying to follow the same pattern. The array named "roles" is deserialized quite correctly. Note the deserializer recognises the array and creates it, but each object is null.

I have tried a number of different approaches, including naming the Propentry member corresponding to "first_name", etc, changing the type of the array, etc., all to no avail.

If anyone has a suggestion as to how to get past this I will be most grateful.
C#
/*
		{"volunteer":
			{
				"id":16838,
//
// other properties successfully deserialized
//
                "roles":[           // this array deserialized successfully
                    {
                        "id":1613,
                        "name":"3Rings Administrator",
                        "suffix":null
                    },
                    {
                        "id":9707,
                        "name":"Mentor",
                        "suffix":""
                    },
                    {
                        "id":1612,
                        "name":"Everyone",
                        "suffix":null
                    }
                ],
                "volunteer_properties":[  // this array not deserialized
                    {
                        "first_name":{
                            "id":3990,
                            "org_name":"First Name",
                            "value":"Richard"
                        }
                    },
                    {"surname":{"id":3991,"org_name":"Surname","value":"MacCutchan "}},
//
// a number of other entries in the same form
//
                ]
			}
		}
*/

//
// the relevant DataContract classes
//
	[DataContract]
	internal class Role		// role items all deserialized successfully
    {
		[DataMember]
		internal int id;
		[DataMember]
		internal string name;
		[DataMember]
		internal string suffix;
	}

    [DataContract]
	internal class Property
    {
		[DataMember]
		internal int id;
		[DataMember]
		internal string org_name;
		[DataMember]
		internal string value;
	}


    [DataContract]
    internal class Propentry
    {
        [DataMember]
        internal Property property;
    }
    [DataContract]
    internal class Properties
    {
        [DataMember]
        internal Propentry propentry;
    }

	// each item contains a number of properties
    [DataContract]
	internal class Volunteer
	{
		[DataMember]
		internal int id;
//
// other members all deserialized successfully
//
		[DataMember]
		internal Role[] roles;
        [DataMember]
        internal Propentry[] volunteer_properties;

    }

	// the main array of items
    [DataContract]
	internal class VolList
	{
		[DataMember]
		internal Volunteer[] volunteers;
	}


modified 18-Jul-19 12:19pm.

AnswerRe: Problem deserialising JSON data Pin
OriginalGriff18-Jul-19 2:35
mveOriginalGriff18-Jul-19 2:35 
GeneralRe: Problem deserialising JSON data Pin
Richard MacCutchan18-Jul-19 3:06
mveRichard MacCutchan18-Jul-19 3:06 
GeneralRe: Problem deserialising JSON data Pin
Richard MacCutchan18-Jul-19 4:05
mveRichard MacCutchan18-Jul-19 4:05 
AnswerRe: Problem deserialising JSON data Pin
Richard Deeming18-Jul-19 4:42
mveRichard Deeming18-Jul-19 4:42 
GeneralRe: Problem deserialising JSON data Pin
Richard MacCutchan18-Jul-19 6:02
mveRichard MacCutchan18-Jul-19 6:02 
QuestionGetting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Member 1453381917-Jul-19 11:29
Member 1453381917-Jul-19 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.