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
C
Sadly the exam got updated this March, here’s the new dump for who’s doing the exam soon.
There’s like 20 new questions with a new case study.
http://megadownloder.com/70483ProgrammingInC
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.
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.
Converts the specified JSON string to an object of type T.
Deserialize(String)
Converts the specified JSON string to an object of type T.
DeserializeObject(String)
Converts the specified JSON string to an object graph.
C is the answer.
Converts the specified JSON string to an object of type T.