开发者

Loss of Precision parsing Floats

开发者 https://www.devze.com 2023-03-13 15:38 出处:网络
When parsing the following JSON string the float value for the x coordinate is being changed. { \"spatialReference\" : {

When parsing the following JSON string the float value for the x coordinate is being changed.

{
 "spatialReference" : {
   "wkid" : 4326
 },
 "candidates" : [
   {
     "address" : "240000001",
     "location" : {
       "x" : -79.939219121531494,
       "y" : 40.85215350688开发者_运维知识库9806
     },
     "score" : 100,
     "attributes" : {

     }
   }
 ]}

Upon calling JObject.Parse on the preceeding xml it is transformed into

 {
  "spatialReference": {
    "wkid": 4326
  },
  "candidates": [
    {
      "address": "240000001",
      "location": {
        "x": -79.9392191215315,
        "y": 40.852153506889806
      },
      "score": 100,
      "attributes": {}
    }
  ]
} 
                         

Is there a way of forcing the parser to treat the x/y values as strings and keep the higher precision?


If you deserialize into a strongly typed object where the x and y properties are decimals then you won't lose any precision.

0

精彩评论

暂无评论...
验证码 换一张
取 消