1

I have a restful wcf service URI like below

http://localhost:8090/WCFRestService.RestServices.svc/1/brands

It's a GET method and return a list of products brands by passing product category ID in JSON format as below:

[
 {
"CategoryId": 1,
"BrandId": 1,
"Name": "ABC"
 },
 {
"CategoryId": 1,
"BrandId": 2,
"Name": "DEF"
 },
 {
"CategoryId": 1,
"BrandIdId": 3,
"Name": "GHI"
 },
 {
"CategoryId": 1,
"BrandIdId": 4,
"Name": "JKL"
 },
 {
"CategoryId": 1,
"BrandIdId": 5,
"Name": "MNO"
 },
 {
"CategoryId": 1,
"BrandIdId": 6,
"Name": "PQR"
 },
 {
"CategoryId": 1,
"BrandIdId": 7,
"Name": "STU"
 }
 ]

I want to bind all these brand names from the json data to a dropdownlist in ASP.Net web application built in .Net 3.5 version. What I have done so far is below:

WebClient proxy = new WebClient();
byte[] abc = proxy.DownloadData((new Uri("http://localhost:8090/WCFRestService.RestServices.svc/1/brands")));
Stream strm = new MemoryStream(abc);
DataContractSerializer obj = new DataContractSerializer(typeof(string));

After this I am unable go further. Can anyone help me out to deserialize and bind it to my dropdownlist? Thank in advance.

Sana
  • 111
  • 1
  • 4
  • 14
  • 1) Verify Json is valid using [Json Lint](http://jsonlint.com/). 2) Create a class to deserialize to, [Json2CSharp](http://json2csharp.com/) is handy for that. 3) Pick a library to use for deserializing, [here's a comparison](http://james.newtonking.com/json/help/html/JsonNetVsDotNetSerializers.htm). 4) Deserialize into the object and bind to your list. – mason Jul 24 '14 at 03:46
  • Check this thread once for how to parse, http://stackoverflow.com/questions/12402085/how-to-parse-json-object-in-c/12402190#12402190 – Raghuveer Jul 24 '14 at 03:49

0 Answers0