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.Desenalize (json, typeof(Name));
B. Return ser.ConvertToType
C. Return ser.Deserialize
D. Return ser.ConvertToType (json, typeof (Name));
The answer should be C, but author forgot add generic parameter .
return ser.Deserialize(json);
another similar question with answer is:
Return ser.Deserialize(json);
for this question, nearest answer is:
Return ser.Deserialize(json);
Correct answer is A. Return ser.Desenalize (json, typeof(Name));
There are only two possible usage of Deserialize:
public T Deserialize(string input);
public object Deserialize(string input, Type targetType);
If we use C. Return ser.Deserialize(json), next error is returned by compiler:
CS0411 C# The type arguments for method cannot be inferred from the usage.
ser.Deserialize (json) ; returns an object which you need to cast to Name. Thus the answers shall be (Name)ser.Deserialize(json, typeof(Name)) or ser.Deserialize(json).
Return ser.Deserialize (json) ;