1

Hi I have to parse json data into datatable object. Bellow is my json data

{

"Figurative Expressions (Idioms)" : {

 "A" : [
         {
            "One word" : "Above all",
            "Phrase" : "chiefly, before everything else"
         },
         {
            "One word" : "Above-board",
            "Phrase" : "not open to question, honest, straight-forward, beyond reproach"
         },
         {
            "One word" : "Above-par",
            "Phrase" : "of superior quality"
         },
         {
            "One word" : "On account of ",
            "Phrase" : "for the sake of"
         },
         {
            "One word" : "On no account",
            "Phrase" : "not for any reason"
         },
         {
            "One word" : "To give a good account of oneself",
            "Phrase" : "to act with credit to oneself"
         }
      ]
   }

}

How do we parse this json data in datatable?

As I tried with javascriptserializer, it was parsed successfully but didn't get anything in datatable.

JavaScriptSerializer js = new JavaScriptSerializer(); 
DataTable data1 = js.Deserialize<DataTable>(text);
5
  • What datatable? Which language are we talking about here? Show some more code -> what have you tried =) Commented Jan 22, 2013 at 8:21
  • I tried with bellow code: JavaScriptSerializer js = new JavaScriptSerializer(); DataTable data1 = js.Deserialize<DataTable>(text); Commented Jan 22, 2013 at 8:24
  • 1
    You can try using Json.Net. See this question and answer: How to convert json into datatable? Commented Jan 22, 2013 at 8:40
  • possible duplicate of How to convert json into datatable? Commented Jan 22, 2013 at 8:42
  • I tried with Json.Net and getting this error "Additional text found in JSON string after finishing deserializing object." Commented Jan 22, 2013 at 9:13

1 Answer 1

0

It could be due to the fact that the Json in your example is not a pure array - but rather an object with one attribute called A which is the actual array.

My suggestion is to try to deserialize only text that defines A attribute (starting with square bracket) - so pure Json array. This should deserialise into a Datatable fine.

Sign up to request clarification or add additional context in comments.

Comments

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.