Created
August 8, 2012 20:15
-
-
Save corymartin/3298227 to your computer and use it in GitHub Desktop.
Parsing JSON array in C# :/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string json = null; | |
| using (var sr = System.IO.File.OpenText("/path/to/persons.json")) { | |
| json = sr.ReadToEnd(); | |
| } | |
| var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); | |
| Person[] users = serializer.Deserialize<Person[]>(json); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Person { | |
| public string name { get; set; }; | |
| public byte age { get; set; }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "name": "Ted", | |
| "age": 34 | |
| }, | |
| { | |
| "name": "Jen", | |
| "age": 29 | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment