0

I have an wikipedia api with json format.I want to make a dynamib´c coding in where id number will be chanced in time. from the api I want to get extract information to show the short description of web page. I modified my json data a little bit from jsonTocSharp. but after parisng the url I am not getting any output. here is my code sample.

 namespace Json_deserialize
 {
  public class pageval
 {
   public int pageid { get; set; }
   public int ns { get; set; }
   public string title { get; set; }
   public string extract { get; set; }
  }


   public class Query
  {
    public Dictionary<string, pageval> pages { get; set; }
   }

   public class Limits
 {
    public int extracts { get; set; }
  }

  public class RootObject
 {
   public string batchcomplete { get; set; }
   public Query query { get; set; }
   public Limits limits { get; set; }
 }

class Short_text
{
  public static RichTextBox txt1 = new RichTextBox();
  public static void shortText()
  {
     using (WebClient wc = new WebClient())
     {
        var client = new WebClient();
        var response = client.DownloadString("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=Neuschwanstein%20Castle&redirects="); ;

        pageval m = JsonConvert.DeserializeObject<pageval>(response);

        string result = m.extract;

        txt1.Text = result;
      }

    }

 }
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user3193794
  • 105
  • 2
  • 12

1 Answers1

2

instead of

   pageval m = JsonConvert.DeserializeObject<pageval>(response);

use

RootObject m = JsonConvert.DeserializeObject<RootObject>(response);
Anik Saha
  • 4,313
  • 2
  • 26
  • 41
  • 1
    What about Keys and values. my code is showing error for keys and values. it shows- Error 'Json_deserialize.Query' does not contain a definition for 'Keys' and no extension method 'Keys' accepting a first argument of type 'Json_deserialize.Query' could be found and another error :The name 'values' does not exist in the current @Anik 1991 – user3193794 Dec 08 '15 at 10:49
  • http://stackoverflow.com/questions/7304002/how-to-parse-a-dynamic-json-key-in-a-nested-json-result This is java version you have do it for C# – Anik Saha Dec 08 '15 at 11:49