Which code segment should you insert at line 10?

An application receives JSON data in the following format:

The application includes the following code segment. (Line numbers are included for reference only.)

You need to ensure that the ConvertToName() method returns the JSON input string as a Name
object.
Which code segment should you insert at line 10?

An application receives JSON data in the following format:

The application includes the following code segment. (Line numbers are included for reference only.)

You need to ensure that the ConvertToName() method returns the JSON input string as a Name
object.
Which code segment should you insert at line 10?

A.
Return ser.ConvertToType<Name>(json);

B.
Return ser.DeserializeObject(json);

C.
Return ser.Deserialize<Name>(json);

D.
Return (Name)ser.Serialize(json);

Explanation:
JavaScriptSerializer.Deserialize<T> – Converts the specified JSON string to an object of type T.
http://msdn.microsoft.com/en-us/library/bb355316.aspx



Leave a Reply 7

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


Lord Vader

Lord Vader

http://stackoverflow.com/questions/9301878/whats-the-difference-between-datacontractjsonserializer-and-javascriptserialize

oth do approximately the same but using very different infrastructure thus applying different restrictions on the classes you want to serialize/deserialize and providing different degree of flexibility in tuning the serialization/deserialization process.

For DataContractJsonSerializer you must mark all classes you want to serialize using DataContract atrtibute and all members using DataMember attribute. As well as if some of you classes have enum members, then the enums also must be marked as DataContract and each enum member – with EnumMember attribute. Also DataContractJsonSerializer allows you fine control over the whole process of serialization/deserialization by altering types resolution logic and replacing the types you serialize with surrogates.

For JavaScriptSerializer you must provide parameterless constructor if you plan on deserializing objects from json string.

Lord Vader

Lord Vader

public T Deserialize(
string input
)

Parameters
input
Type: System.String
The JSON string to be deserialized.
Return Value
Type: T
The deserialized object.
Type Parameters
T
The type of the resulting object.

Lord Vader

Lord Vader

Converts the specified JSON string to an object of type T.

Lord Vader

Lord Vader

Deserialize(String)
Converts the specified JSON string to an object of type T.
DeserializeObject(String)
Converts the specified JSON string to an object graph.

YouCrackedMeUp

YouCrackedMeUp

C is the answer.

Converts the specified JSON string to an object of type T.