【问题标题】:How to change JSON API label into number in .net如何将 JSON API 标签更改为 .net 中的数字
【发布时间】:2021-11-19 08:36:55
【问题描述】:

所以目前我正在使用 react-simple-map 制作带有标记的地图。它需要这种 json 格式:

[{
   "coordinates":{
      "0":139.6917,
      "1":35.6480
   },
      "name":"Tokyo",
  },
  {
    "coordinates":{
      "0":101.9758,
      "1":4.2105
    },
    "name":"Malaysia",
}]

然后我尝试像这样更改 .net 中的标签:

 public IQueryable<Object> GetCoordination()
        {
            return from a in _awContext.SalesTerritories
                   join p in _awContext.Coordination
                   on a.TerritoryId equals p.TerritoryID
                   select new
                   {
                       id = a.TerritoryId,
                       coordinates = new 
                       {
                           '0' = p.Lat,
                           '1' = p.Long,    
                       },
                       name = a.Name,
                       countryRegionCode = a.CountryRegionCode,
                       salesYtd = a.SalesYtd,
                       salesLastYear = a.SalesLastYear,
                       costYtd = a.CostYtd,
                       costLastYear = a.CostLastYear,

                   };
        }

发生的情况是 0 和 1 有错误。

有没有办法让它成为整数。

【问题讨论】:

    标签: reactjs .net react-simple-maps


    【解决方案1】:

    你不应该有数组键

    {
        "coordinates": [0.1234,1.2345]
    }
    

    干杯!

    【讨论】:

    • “纬度”:139.6917,“长”:35.64。 json变成了这样。如果我做坐标 = new { p.Lat, p.Long },
    • 你测试过这个吗? : 坐标 = [p.Lat, p.Long]
    • Yes this 1 return invalid expression "["
    • 所以我把它改成了坐标 = new { p.Lat, p.Long }
    猜你喜欢
    • 2021-12-26
    • 2023-02-09
    • 2021-11-04
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多