c# - Trying to parse a RESTful api response -
I have a problem, and I can not find a clue on how Google solved it. I am trying to parse the reaction of a Resist-API service.
[{"account_id": "5401585", "history": "8496786 9 | 2 | 03/30/2012, 84972342 | 2 | 03 \ / 30 \ / 2012, 85312563 | 2 | 04/02/2 012,85314831 | 2 | 04/02/20128518547 | 02/04/02/201285435388 | 2 | 04/03 / 2012,100244102 | 2 | 09 \ / 09 \ / 2012,100 245865 | 2 | 09 \ / 09 \ / 2012,100249440 | 2 | 09 \ / 2012 | 100251434 | 2 | 09 \ / 2012 \ "/> > I do not think my response as a list says my model.
Basically, I want every line added to "," to a list.
My code looks like this:
Public Class MatchHistoryParser {Get the public route object () ({Var webClient = New System.Net.WebClient ()) Experiment {string URL2 = @ "API URL"; Var json = webClient.DownloadString (URL2); Root Object Match = Jason Convert. Directoryal Object & lt; Root object & gt; (JSN); Return match; }}} Public class RootObject {public string account_id {get; Set; } Public string history {get; Set; } Public string win_loss_history {get; Set; }} throws an error: "Additional information: Can not change existing JSON array (like [1,2,3]) to 'HoNEnemy.BL.RootObject' type because type Required JSON object (such as {"name": "value"}) to properly deserialize. "
You are not able to get a list, an object, so you should parse this way
root object root object; Var Matches = Jason Convert. Directoryal Object & lt; IList & lt; RootObject & gt; & Gt; (JSN); then
if (matches.Any ()) {rootObject = matches [0]; } and then create a method to divide history strings into a list and use it, not property
Comments
Post a Comment