Click here to Skip to main content
15,881,898 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Luc Pattyn17-Jul-19 11:49
sitebuilderLuc Pattyn17-Jul-19 11:49 
GeneralRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Member 1453381917-Jul-19 12:00
Member 1453381917-Jul-19 12:00 
GeneralRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Luc Pattyn17-Jul-19 12:13
sitebuilderLuc Pattyn17-Jul-19 12:13 
AnswerRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Eddy Vluggen17-Jul-19 13:51
professionalEddy Vluggen17-Jul-19 13:51 
AnswerRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
phil.o17-Jul-19 22:13
professionalphil.o17-Jul-19 22:13 
AnswerRe: Getting Exception Window Class Name is not Valid in Windows Application using vb.net Pin
Richard Deeming17-Jul-19 22:52
mveRichard Deeming17-Jul-19 22:52 
QuestionOutOfMemoryException help please Pin
DTGeek17-Jul-19 5:07
DTGeek17-Jul-19 5:07 
AnswerRe: OutOfMemoryException help please Pin
OriginalGriff17-Jul-19 5:21
mveOriginalGriff17-Jul-19 5:21 
AnswerRe: OutOfMemoryException help please Pin
Gerry Schmitz17-Jul-19 6:07
mveGerry Schmitz17-Jul-19 6:07 
GeneralRe: OutOfMemoryException help please Pin
DTGeek17-Jul-19 6:11
DTGeek17-Jul-19 6:11 
AnswerRe: OutOfMemoryException help please Pin
Luc Pattyn17-Jul-19 7:42
sitebuilderLuc Pattyn17-Jul-19 7:42 

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.