Which code segment should you use?

You are developing a C# application. The application references and calls a RESTful web service
named EmployeeService. The EmployeeService web service includes a method named GetEmployee,
which accepts an employee ID as a parameter. The web service returns the following JSON data from
the method.
{“Id”:1,”Name”:”David Jones”>
The following code segment invokes the service and stores the result:

You need to convert the returned JSON data to an Employee object for use in the application.
Which code segment should you use?

You are developing a C# application. The application references and calls a RESTful web service
named EmployeeService. The EmployeeService web service includes a method named GetEmployee,
which accepts an employee ID as a parameter. The web service returns the following JSON data from
the method.
{“Id”:1,”Name”:”David Jones”>
The following code segment invokes the service and stores the result:

You need to convert the returned JSON data to an Employee object for use in the application.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 3

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


Najlepszy Programista Swiata DAGO

Najlepszy Programista Swiata DAGO

C

Twórca C#

Twórca C#

Correct.DAGO I’m happy that you understand my language C# so good.

Lord Vader

Lord Vader

if hte question was to deserialize XML it would be interesting:

Dan Rigsby has the ultimate post on this – go read it!

XmlSerializer vs. DataContractSerializer (web archive)

He says all there is to say, and it a very convincing way.

In short:

XmlSerializer:

has been around for a long time
is “opt-out”; everything public gets serialized, unless you tell it not to ([XmlIgnore])
DataContractSerializer is:

the new kid in town
optimized for speed (about 10% faster than XmlSerializer, typically)
“opt-in” – only stuff you specifically mark as [DataMember] will be serialized
but anything marked with [DataMember] will be serialized – whether it’s public or private
doesn’t support XML attributes (for speed reasons)