0

I have this json file

[{"Ticker":"610-KW",
"Ric_Code":null,
"Business_Description":"Sultan Center Food Products Company KSCC is a Kuwait-based public shareholding company that holds investments in diverse portfolio of companies within Kuwait and the Middle East, with a specific focus on the retail industry. The Company’s activities include the construction of central markets and restaurants; import, export and marketing of consumer goods; manufacturing of food products; operation of retail supermarkets, restaurants and catering services; trade and installation of telecommunication equipment; trade in readymade garments, shoes, suits, accessories and gifts, and investment in real estate and other industries. The Company also provides consulting and training services. Its business units are structured into seven divisions namely retail, restaurants, trading, fashion, telecom, security and investments. The Company owns and operates subsidiaries in Kuwait, Oman, Bahrain, Lebanon, Jordan, the United Arab Emirates, Egypt and Syria."
,"Arabic_Name":"شركة مركز سلطان للمواد الغذائية (ش.م.ك.مقفلة)","English_Name":"SULTAN CENTER FOOD PRODUCTS COMPANY - K.S.C. (CLOSED)",
"ValidationQuarters":
[{"Period_End_Date":"2012-09-30T00:00:00","Purification_Percentage":0.0,"Status":"Fail","Standard":"QRC","OutStandingShares":578828800,"Treasury_Shares":null,"WhiteList":null}]}

and i created this classes to deserialize it

public class ValidationQuarter
 {
 public string Period_End_Date { get; set; }
 public double Purification_Percentage { get; set; }
 public string Status { get; set; }
 public string Standard { get; set; }
 public int OutStandingShares { get; set; }
 public int? Treasury_Shares { get; set; }
 public object WhiteList { get; set; }
 }
 public class QueryResult
 {
 public string Ticker { get; set; }
 public object Ric_Code { get; set; }
 public string Business_Description { get; set; }
 public string Arabic_Name { get; set; }
 public string English_Name { get; set; }
 public List<ValidationQuarter> ValidationQuarters { get; set; }
 }

When called this code

string result = c.getResultsByTicker(reqStr);
 QueryResult qr = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryResult>(result);

It raises an error

Cannot deserialize JSON array into type 'webservicetry.QueryResult'. Line 1, position 1.

marc_s
759k185 gold badges1.4k silver badges1.5k bronze badges
asked May 11, 2013 at 20:39

1 Answer 1

2

Your JSON represents an array of QueryResult objects. You're trying to deserialize them as a single instance. You just need to change to:

List<QueryResult> qrs = JsonConvert.DeserializeObject<List<QueryResult>>(result);
answered May 11, 2013 at 20:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.