Which code segment should you use?

You are developing an application that retrieves patient data from a web service. The application
stores the JSON messages returned from the web service in a string variable named PatientAsJson.
The variable is encoded as UTF-8. The application includes a class named Patient that is defined by
the following code:

You need to populate the Patient class with the data returned from the web service.
Which code segment should you use?

You are developing an application that retrieves patient data from a web service. The application
stores the JSON messages returned from the web service in a string variable named PatientAsJson.
The variable is encoded as UTF-8. The application includes a class named Patient that is defined by
the following code:

You need to populate the Patient class with the data returned from the web service.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 4

Your email address will not be published. Required fields are marked *


SafeHub

Mike

Mike

I agree with you and also say it is A. But the Question is wrong as your link states clearly:
“1.) Define the data contract for Person by attaching the DataContractAttribute to the class and DataMemberAttribute attribute to the members you want to serialize. For more information about data contracts, see Designing Service Contracts.”

Lord Vader

Lord Vader

DataContractJsonSerializer.WriteObject
Serializes a specified object to JavaScript Object Notation (JSON) data and writes the resulting JSON to a stream.
we want to read from a stream and write to an object. this reads an object and writes to a stream.

DataContractJsonSerializer.ReadObject
Reads a document stream in the JSON (JavaScript Object Notation) format and returns the deserialized object.
we want to read from a stream and write to an object. bingo

xmlserializer/binaryformatter cant interpret json so u have garbage data stored in the patient obj