c# - NewtonSoft JArray - how to select multiple elements with LINQ -


I have some Jason which I then parsed the Jerry object. I want to filter Jerere so that he has only two properties, title and bodytext. But whatever I try I can only select a value using LINQ

  [HttpGet] Public JsonResult AjaxGetNewsItems () {string json = JsonConvert.SerializeObject (news.GetNewsItems (), Formatting: formatting.Indented); Var v = Jairo Purse (jason); // arrow item = // v.Where (// X =>.! // X ["title"] ToString () = string.Empty & amp; //X ["BodyText"] ToString ()! = String.Empty) // Select (x = & gt; x ["title"]) // .toList (); Var title = (string) v [0] ["title"]; Var titleBodytext = v selectively v [0] ["title"] ["bodytext"]; Foreach (item in titleBodytext) {} // Title: Biodtext = // v [0] ["title"] ["BodyText"] by c // // Group c // new selection from c in gram // {}; // JArray a = JArray.FromObject (news.GetNewsItems ()); // string titlebodietext = (string) news item ["title"] ["bodytext"]; Return the new Jason result () {Data = JSON, Jasonuefiestbihair = Jasonoffest Behavior.Olowett, Maxxson Langel = Int. 32.MaxValue}; }  

I want to change this code: [0] ["title"] ["BodyText"] from the selection of title in Binarytext = V on

  ];  

title and bodytext have two key values ​​in my JArray

See a screenshot of the JArray object. Element 0 contains the main values ​​element.

Try this way:

  var titleBodytext = v Select new in p {title = (string) p ["title"], text = (string) p ["bodytext"]};  

Or if you are sure that v always contains the same element:

  var titleBodytext = new {title = (String)) V [0] ["title"], text = (string) v [0] ["bodytext"]};  

BTW, your current code does not look like what you think. In the p

to section, always select v [0] regardless of the current p context . Anyway, it does not show the wrong behavior in the case where there is only one element in v .


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -