kevin-montrose / Jil

Fast .NET JSON (De)Serializer, Built On Sigil
MIT License
2.15k stars 254 forks source link

Deserialization throws 'Input string was not in a correct format.' #77

Closed amacal closed 10 years ago

amacal commented 10 years ago

I am going to deserialize the following JSON

{
  "query": {
    "params": {
      "accuracy": 0,
      "autocomplete": false,
      "granularity": "neighborhood",
      "query": "Toronto",
      "trim_place": false
    },
    "type": "search",
    "url": "https://api.twitter.com/1.1/geo/search.json?accuracy=0&query=Toronto&granularity=neighborhood&autocomplete=false&trim_place=false"
  },
  "result": {
    "places": [
      {
        "attributes": {},
        "bounding_box": {
          "coordinates": [
            [
              [
                -96.647415,
                44.566715
              ],
              [
                -96.630435,
                44.566715
              ],
              [
                -96.630435,
                44.578118
              ],
              [
                -96.647415,
                44.578118
              ]
            ]
          ],
          "type": "Polygon"
        },
        "contained_within": [
          {
            "attributes": {},
            "bounding_box": {
              "coordinates": [
                [
                  [
                    -104.057739,
                    42.479686
                  ],
                  [
                    -96.436472,
                    42.479686
                  ],
                  [
                    -96.436472,
                    45.945716
                  ],
                  [
                    -104.057739,
                    45.945716
                  ]
                ]
              ],
              "type": "Polygon"
            },
            "country": "United States",
            "country_code": "US",
            "full_name": "South Dakota, US",
            "id": "d06e595eb3733f42",
            "name": "South Dakota",
            "place_type": "admin",
            "url": "https://api.twitter.com/1.1/geo/id/d06e595eb3733f42.json"
          }
        ],
        "country": "United States",
        "country_code": "US",
        "full_name": "Toronto, SD",
        "id": "3e8542a1e9f82870",
        "name": "Toronto",
        "place_type": "city",
        "url": "https://api.twitter.com/1.1/geo/id/3e8542a1e9f82870.json"
      },
      {
        "attributes": {},
        "bounding_box": {
          "coordinates": [
            [
              [
                -80.622815,
                40.436469
              ],
              [
                -80.596567,
                40.436469
              ],
              [
                -80.596567,
                40.482566
              ],
              [
                -80.622815,
                40.482566
              ]
            ]
          ],
          "type": "Polygon"
        },
        "contained_within": [
          {
            "attributes": {},
            "bounding_box": {
              "coordinates": [
                [
                  [
                    -84.820305,
                    38.403423
                  ],
                  [
                    -80.518454,
                    38.403423
                  ],
                  [
                    -80.518454,
                    42.327132
                  ],
                  [
                    -84.820305,
                    42.327132
                  ]
                ]
              ],
              "type": "Polygon"
            },
            "country": "United States",
            "country_code": "US",
            "full_name": "Ohio, US",
            "id": "de599025180e2ee7",
            "name": "Ohio",
            "place_type": "admin",
            "url": "https://api.twitter.com/1.1/geo/id/de599025180e2ee7.json"
          }
        ],
        "country": "United States",
        "country_code": "US",
        "full_name": "Toronto, OH",
        "id": "53d949149e8cd438",
        "name": "Toronto",
        "place_type": "city",
        "url": "https://api.twitter.com/1.1/geo/id/53d949149e8cd438.json"
      },
      {
        "attributes": {},
        "bounding_box": {
          "coordinates": [
            [
              [
                -79.639128,
                43.403221
              ],
              [
                -78.90582,
                43.403221
              ],
              [
                -78.90582,
                43.855466
              ],
              [
                -79.639128,
                43.855466
              ]
            ]
          ],
          "type": "Polygon"
        },
        "contained_within": [
          {
            "attributes": {},
            "bounding_box": {
              "coordinates": [
                [
                  [
                    -95.155919,
                    41.676329
                  ],
                  [
                    -74.339383,
                    41.676329
                  ],
                  [
                    -74.339383,
                    56.852398
                  ],
                  [
                    -95.155919,
                    56.852398
                  ]
                ]
              ],
              "type": "Polygon"
            },
            "country": "Canada",
            "country_code": "CA",
            "full_name": "Ontario, Canada",
            "id": "89b2eb8b2b9847f7",
            "name": "Ontario",
            "place_type": "admin",
            "url": "https://api.twitter.com/1.1/geo/id/89b2eb8b2b9847f7.json"
          }
        ],
        "country": "Canada",
        "country_code": "CA",
        "full_name": "Toronto, Ontario",
        "id": "8f9664a8ccd89e5c",
        "name": "Toronto",
        "place_type": "city",
        "url": "https://api.twitter.com/1.1/geo/id/8f9664a8ccd89e5c.json"
      },
      {
        "attributes": {},
        "bounding_box": {
          "coordinates": [
            [
              [
                -90.867234,
                41.898723
              ],
              [
                -90.859467,
                41.898723
              ],
              [
                -90.859467,
                41.906811
              ],
              [
                -90.867234,
                41.906811
              ]
            ]
          ],
          "type": "Polygon"
        },
        "contained_within": [
          {
            "attributes": {},
            "bounding_box": {
              "coordinates": [
                [
                  [
                    -96.639485,
                    40.375437
                  ],
                  [
                    -90.140061,
                    40.375437
                  ],
                  [
                    -90.140061,
                    43.501196
                  ],
                  [
                    -96.639485,
                    43.501196
                  ]
                ]
              ],
              "type": "Polygon"
            },
            "country": "United States",
            "country_code": "US",
            "full_name": "Iowa, US",
            "id": "3cd4c18d3615bbc9",
            "name": "Iowa",
            "place_type": "admin",
            "url": "https://api.twitter.com/1.1/geo/id/3cd4c18d3615bbc9.json"
          }
        ],
        "country": "United States",
        "country_code": "US",
        "full_name": "Toronto, IA",
        "id": "173d6f9c3249b4fd",
        "name": "Toronto",
        "place_type": "city",
        "url": "https://api.twitter.com/1.1/geo/id/173d6f9c3249b4fd.json"
      },
      {
        "attributes": {},
        "bounding_box": {
          "coordinates": [
            [
              [
                -95.956873,
                37.792724
              ],
              [
                -95.941288,
                37.792724
              ],
              [
                -95.941288,
                37.803752
              ],
              [
                -95.956873,
                37.803752
              ]
            ]
          ],
          "type": "Polygon"
        },
        "contained_within": [
          {
            "attributes": {},
            "bounding_box": {
              "coordinates": [
                [
                  [
                    -102.051769,
                    36.993016
                  ],
                  [
                    -94.588387,
                    36.993016
                  ],
                  [
                    -94.588387,
                    40.003166
                  ],
                  [
                    -102.051769,
                    40.003166
                  ]
                ]
              ],
              "type": "Polygon"
            },
            "country": "United States",
            "country_code": "US",
            "full_name": "Kansas, US",
            "id": "27c45d804c777999",
            "name": "Kansas",
            "place_type": "admin",
            "url": "https://api.twitter.com/1.1/geo/id/27c45d804c777999.json"
          }
        ],
        "country": "United States",
        "country_code": "US",
        "full_name": "Toronto, KS",
        "id": "b90e4628bff4ad82",
        "name": "Toronto",
        "place_type": "city",
        "url": "https://api.twitter.com/1.1/geo/id/b90e4628bff4ad82.json"
      }
    ]
  }
}

into Twitter class using the following class definition

    public class Twitter
    {
        public Query query { get; set; }
        public Result result { get; set; }

        public class Query
        {
            public Parameters @params { get; set; }
            public string type { get; set; }
            public string url { get; set; }
        }

        public class Parameters
        {
            public int accuracy { get; set; }
            public bool autocomplete { get; set; }
            public string granularity { get; set; }
            public string query { get; set; }
            public bool trim_place { get; set; }
        }

        public class Result
        {
            public Place[] places { get; set; }
        }

        public class Place
        {
            public Attributes attributes { get; set; }
            public BoundingBox bounding_box { get; set; }
            public Place[] contained_within { get; set; }

            public string country { get; set; }
            public string country_code { get; set; }
            public string full_name { get; set; }
            public string id { get; set; }
            public string name { get; set; }
            public string place_type { get; set; }
            public string url { get; set; }
        }

        public class Attributes
        {
        }

        public class BoundingBox
        {
            public double[][] coordinates  { get; set; }
            public string type { get; set; }
        }
    }

and I receive the following exception. My system culture is Polish.

Input string was not in a correct format.

   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Double.Parse(String s, IFormatProvider provider)
   at Jil.Deserialize.Methods._ReadDoubleCharArray(TextReader reader, Char[]& buffer)
   at _DynamicMethod0(TextReader , Int32 )
   at _DynamicMethod7(TextReader , Int32 )
   at _DynamicMethod9(TextReader , Int32 )
   at Jil.JSON.Deserialize[T](TextReader reader, Options options)
amacal commented 10 years ago

My mistake. I didn't noticed tripple array.