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 3

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


Swapnil

Swapnil

public static Name ConvertToName(string json)
{
var ser = new JavaScriptSerializer();
return ser.Deserialize(json);
}
static void Main(string[] args)
{
string json=”{‘FirstName’:’Swapnil’, ‘LastName’:’Gaikwad’,’Values’:[0,1,2]}”;

var name = Program.ConvertToName(json);
Console.WriteLine(name.FirstName);
Console.ReadLine();

Si

Si

From your code I’m assuming that’s Answer C. The compiler is inferring the type from the methods return type.

return ser.Deserialize(json);

is really

return ser.Deserialize(json);

Si

Si

Ah, I see that this comments section of this site is removing greater than and less than symbols and their content!