Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Razor JSON to list
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Skythrust" data-source="post: 476655" data-attributes="member: 87030"><p>Hi all,</p><p></p><p>I was wondering if there are any possibilities to show all values from an JSON output in a list.</p><p></p><p>For now I am able to show just one value, but in the foreach I would like to show them all.</p><p>[CODE=csharp]c#</p><p></p><p>JSON output/response is; [{"FrstName": "John","LastName": "Doe","MiddleName": null,},{"FrstName": "Jane","LastName": "Doe","MiddleName": null,},{"FrstName": "Hope","LastName": "Dyne","MiddleName": van,}]</p><p></p><p>dynamic jsonResponse = JsonConvert.DeserializeObject(response.Content);</p><p></p><p>Persons = new List<Person>();</p><p></p><p>Persons.Add(new Person()</p><p>{</p><p> FrstName = jsonResponse.FrstName, // FrstName = jsonResponse[0].FrstName</p><p> LastName = jsonResponse.LastName, // LastName = jsonResponse[0].LastName</p><p> MiddleName = jsonResponse.MiddleName, // MiddleName = jsonResponse[0].MiddleName</p><p>});[/CODE]</p><p></p><p>with the [0] it works for just one record.</p></blockquote><p></p>
[QUOTE="Skythrust, post: 476655, member: 87030"] Hi all, I was wondering if there are any possibilities to show all values from an JSON output in a list. For now I am able to show just one value, but in the foreach I would like to show them all. [CODE=csharp]c# JSON output/response is; [{"FrstName": "John","LastName": "Doe","MiddleName": null,},{"FrstName": "Jane","LastName": "Doe","MiddleName": null,},{"FrstName": "Hope","LastName": "Dyne","MiddleName": van,}] dynamic jsonResponse = JsonConvert.DeserializeObject(response.Content); Persons = new List<Person>(); Persons.Add(new Person() { FrstName = jsonResponse.FrstName, // FrstName = jsonResponse[0].FrstName LastName = jsonResponse.LastName, // LastName = jsonResponse[0].LastName MiddleName = jsonResponse.MiddleName, // MiddleName = jsonResponse[0].MiddleName });[/CODE] with the [0] it works for just one record. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Razor JSON to list
Top