2
http://www.taxmann.com/TaxmannWhatsnewService/Services.aspx?service=gettopstoriestabnews 

This is my web service I have to parse and store all value in String please help me how to parse.

using asp.net (C#) so that I can store :

news_id  as it variable

news_title as  title variable

news_short_description   as description

news_date as date ;

Please help me I'm new in .net I tried but not able to do

3
  • 1
    Please don't use "plz" but "please". Commented Mar 24, 2012 at 10:51
  • 2
    I guess even better would have been "plz don't use 'plz' but 'please' " :P Commented Mar 24, 2012 at 10:53
  • maybe this help ? stackoverflow.com/questions/1212344/parse-json-in-c-sharp Commented Mar 24, 2012 at 10:58

3 Answers 3

2

You can use this class

public class News
{
    public string news_id;
    public string news_title;
    public string news_short_description;
    public string news_date;
}

to deserialize the response string

using (var wc = new WebClient())
{
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    var result =  serializer.Deserialize<News[]>(wc.DownloadString("http://www.taxmann.com/TaxmannWhatsnewService/Services.aspx?service=gettopstoriestabnews"));
    foreach (var item in result)
    {
        Console.WriteLine(item.news_title);
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanyou very much i got oout put i want this thing
can u plz bind the data so that we can display in listview
@AnilKumar You asked something and got your answer. You canceled your accept since I didn't answer your second question? Not nice. Don't be a help vampire
2

First download a JSON library from here. And add reference to your project (Right click to your project=>Add reference=> NewtonSoft.Json.dll). After that do some coding...

using System.Newtonsoft.Json;
using System.Newtonsoft.Json.Linq;
using System.Net;

 static void Main(string[] args)
    {
        WebClient c = new WebClient();
        var data = c.DownloadString("http://www.taxmann.com/TaxmannWhatsnewService/Services.aspx?service=gettopstoriestabnews");

        JObject o = JObject.Parse(data);
        Response.Write("NewsID: "+ o["news_id"]);
        Response.Write("NewsTitle: " + o["news_title"]);


    }

Comments

1

You can also use "DataContractJsonSerializer" instead of JavaScriptSerializer, it's the component used by WCF to (de)serialize JSON Read this for more info: http://publicityson.blogspot.com/2010/06/datacontractjsonserializer-versus.html

3 Comments

Avoid DCJS. It's less flexible when [de]serializing Enums, DateTimes, Anonymous Types, and produces larger than necessary (incorrect, IMO) JSON for Dictionaries.
Yes there are drawback. But JavaScriptSerializer doesn't handle recursivity correctly (if you have object referencing itself via references to other objects). So each components have pro & cons, it's why I linked the article.
@Fabske You can also use "DataContractJsonSerializer" instead of JavaScriptSerializer OP doesn't use anything. This is not an answer, just a comment to my answer. And I, personally, prefer Json.Net whenever I have the option to choose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.