Professional Documents
Culture Documents
U6 M1 L6 Annotated - Tagged
U6 M1 L6 Annotated - Tagged
U6 M1 L6 Annotated - Tagged
Processing
Objects
{
“first_name”: “Janaka”
“last_name”: “Balasooriya”
“address”: {
“street”: “ mill ave”
“city”: “tempe”
“zipcode”: 85281
}
phone: [“121-324”, “122-341”]
}
String array
Processing API JSON Result C# Code
string url =
@"http://localhost:22815/Service1.svc/setNameAge?
f_name=Janaka&l_name=Bala";
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
personInfo p =
JsonConvert.DeserializeObject<personInfo>(json);
Console.WriteLine(p.first_name);
Console.WriteLine(p.address.city);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; static void processJsonJavaScriptSerializer(String
using System.Text; data)
using System.Net.Http; {
using System.Net; JavaScriptSerializer js = new
using System.Text; JavaScriptSerializer();
using System.IO; personInfo p = js.Deserialize<personInfo>(data);
using Newtonsoft.Json; Console.WriteLine(p.first_name);
using System.Web.Script.Serialization;
namespace Client }
{
class Program // Beginning of the program
{
static void Main(string[] args)
{
string url = @"http://localhost:22815/Service1.svc/setNameAge?
f_name=Janaka&l_name=Bala";
processJsonJavaScriptSerializer(json);
processJsonNewtonSoft(json);
}
}
static void processJsonNewtonSoft(String data)
{
personInfo p =
JsonConvert.DeserializeObject<personInfo>(data);
Console.WriteLine(p.address.city);
}
Complete Code
[Serializable]
Objects
public class personInfo {
{ “first_name” : “Janaka”
public string first_name { get; set;
}
“last_name”: “Balasooriya”
public string last_name { get; “address” : {
set; } “street”: “ mill ave”
public Address address { get; set; } “city” : “tempe”
public string[] phone { get; set; }
}
“zipcode”: 85281
}
public class Address phone : [“121-324”, “122-341”]
{ }
public string street { get; set; }
public string city { get; set; } String array
public int zipcode { get; set; }
}