using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization.Json;
using System.Text;
namespace WebApplication21
{
[Serializable]
public class GooglePage
{
public string start;
public string label;
}
[Serializable]
public class GoogleResponseCursor
{
public GooglePage[] pages;
public int estimatedResultCount;
public int currentPageIndex;
public string moreResultsUrl;
}
[Serializable]
public class GoogleResponseData
{
public string[] results;
public GoogleResponseCursor cursor;
}
[DataContract]
public class ResponseData
{
[DataMember(Name = "responseData")]
public ResultList responseData
{ get; set; }
[DataMember(Name = "responseDetails")]
public string responseDetails
{ get; set; }
[DataMember(Name = "responseStatus")]
public string responseStatus
{ get; set; }
}
[DataContract]
public class ResultList
{
[DataMember(Name = "results")]
public GsearchResultClass[] GResult
{ get; set; }
}
[DataContract]
public class GsearchResultClass
{
[DataMember(Name = "GsearchResultClass")]
public string GsearchResult
{ get; set; }
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string soaprequest = "{\"responseData\":{\"results\":[{\"GsearchResultClass\":\"GwebSearch\",\"unescapedUrl\":\"http://en.wikipedia.org/wiki/Paris_Hilton\",\"url\":\"http://en.wikipedia.org/wiki/Paris_Hilton\",\"visibleUrl\":\"en.wikipedia.org\",\"titleNoFormatting\":\"Paris Hilton - Wikipedia, the free encyclopedia\"},{\"GsearchResultClass\":\"GwebSearch\",\"unescapedUrl\":\"http://www.imdb.com/name/nm0385296/\",\"url\":\"http://www.imdb.com/name/nm0385296/\",\"visibleUrl\":\"www.imdb.com\",\"titleNoFormatting\":\"Paris Hilton\"}],\"cursor\":{\"pages\":[{\"start\":\"0\",\"label\":1}, {\"start\":\"4\",\"label\":2},{\"start\":\"8\",\"label\": 3 },{\"start\":\"12\",\"label\":4}],\"estimatedResultCount\":\"59600000\",\"currentPageIndex\": 0,\"moreResultsUrl\":\"http://www.google.com/search?oe\"}},\"responseDetails\": null,\"responseStatus\": 200}";
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseData));
byte[] respBytes = ASCIIEncoding.UTF8.GetBytes(soaprequest);
using (StreamReader reader = new StreamReader(new MemoryStream(respBytes)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ResponseData));
ResponseData returnObj = (ResponseData)serializer.ReadObject(reader.BaseStream);
}
}
}
}
|