How to parse.

var s = JsonConvert.DeserializeObject<Test>(@"{ 'streetAddress:word': 'Московское ш., 201, кв.200', 'city': 'Москва', 'postalCode': 201201 },{ 'streetAddress:word': 'Московское ш., 201, кв.220', 'city': 'Тверь', 'postalCode': 2222 }"); 
  • Well, it looks right, what's the problem? - Monk
  • @Monk, in that several objects are trying to not merged into an array - Grundy
  • add [ , ] around json: @"[{...},{...}]" and parse as Test[] - Grundy
  • I need option 2 to get a decimal point - Test132234324
  • one
    just deserialize it only - Grundy

2 answers 2

Using the Grundy comment and a site that easily gives a model for json ( http://jsonutils.com/ )

 using System.Linq; using Newtonsoft.Json; namespace _608123 { static class Program { static void Main(string[] args) { var json = @"[{ 'streetAddress:word': 'Московское ш., 201, кв.200', 'city': 'Москва', 'postalCode': 201201 },{ 'streetAddress:word': 'Московское ш., 201, кв.220', 'city': 'Тверь', 'postalCode': 2222 }]"; var examples = Newtonsoft.Json.JsonConvert.DeserializeObject<Example[]>(json); var lastExample = examples.Last(); } } public class Example { [JsonProperty("streetAddress:word")] public string streetAddress { get; set; } [JsonProperty("city")] public string city { get; set; } [JsonProperty("postalCode")] public int postalCode { get; set; } } } 
     var json = "мой json"; List<Test> test= JsonConvert.DeserializeObject<List<Test>>(json,new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }); Test p1 = test[0]; Test p2 = test[1]; Test p3 = test[2]; 
    • How does this code differ from the code in question? - Grundy