PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 20?

You are developing an application. The application converts a Location object to a string by using a
method named WriteObject. The WriteObject() method accepts two parameters, a Location object
and an XmlObjectSerializer object.
The application includes the following code. (Line numbers are included for reference only.)

You need to serialize the Location object as a JSON object.
Which code segment should you insert at line 20?

PrepAway - Latest Free Exam Questions & Answers

A.
New DataContractSerializer(typeof(Location))

B.
New XmlSerializer(typeof(Location))

C.
New NetDataContractSenalizer()

D.
New DataContractJsonSerializer(typeof(Location))

Explanation:
The DataContractJsonSerializer class serializes objects to the JavaScript Object Notation (JSON) and
deserializes JSON data to objects.
Use the DataContractJsonSerializer class to serialize instances of a type into a JSON document and to
deserialize a JSON document into an instance of a type.

7 Comments on “Which code segment should you insert at line 20?

  1. sv1slim says:

    “The WriteObject() method accept two parameters, a Location object and a XmlObjectSerializer object” – the expression is confusing but I get now.

    public sealed class DataContractJsonSerializer : XmlObjectSerializer




    1



    0
  2. Lord Vader says:

    System.Object
      System.Runtime.Serialization.XmlObjectSerializer
        System.Runtime.Serialization.DataContractSerializer
        System.Runtime.Serialization.Json.DataContractJsonSerializer
        System.Runtime.Serialization.NetDataContractSerializer

    Use the DataContractSerializer/DataContractJsonSerializer class to serialize and deserialize instances of a type into an XML/JSON stream or document.

    The NetDataContractSerializer differs from the DataContractSerializer in one important way: the NetDataContractSerializer includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the NetDataContractSerializer can be used only if both the serializing and deserializing ends share the same CLR types.

    System.Object
      System.Xml.Serialization.XmlSerializer

    has to be D




    0



    0

Leave a Reply