string jsonString = "{\"name\":\"John\", \"age\":30}"; var context = new JsonUnmarshallerContext(jsonString); var person = JsonMapper.ToObject(context.ReadText());
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { var context = new JsonUnmarshallerContext(response.GetResponseStream()); var user = JsonMapper.ToObjectIn this example, we send a HttpWebRequest to an API endpoint and get the response stream. We then pass this stream to a new JsonUnmarshallerContext object and use the Read() method to read the JSON data from the context and convert it to a User object. Package Library: This class is part of the AWSSDK.Core NuGet package library.(context.Read()); }
Read()
operation gets the next token. TestExpression()
is used to match the current key-chain to an xpath expression. The general pattern looks like this: JsonUnmarshallerContext context = new JsonUnmarshallerContext(jsonString); while (context.Read()) { if (context.IsKey) { if (context.TestExpresion("path/to/element")) { myObject.stringMember = stringUnmarshaller.GetInstance().Unmarshall(context); continue; } } }