JSON对象转成dynamic如何获取属性

CottZheng 2016-08-04 03:11:04
这有一个GeoJSON对象,我把它转换成dynamic类型变量dy

{"type":"GeometryCollection","geometries":[
{"type":"Point","coordinates":[-342419109908.69024,146751047103.7244]},
{"type":"Point","coordinates":[-230354673938.57346,-36465411704.56182]},
{"type":"Point","coordinates":[-13341004282.156763,-57811018556.01264]},
{"type":"Point","coordinates":[111175035684.6397,73820223694.60075]},
{"type":"Point","coordinates":[89829428833.18887,258815483073.84122]},
{"type":"Point","coordinates":[-107617434542.73123,322852303628.19366]},
{"type":"Point","coordinates":[-239248676793.34463,255257881931.93274]}
]}

我可以通过dy.type获取到geometrycollection,我如果想获取到Point和坐标值,该如何操作?
...全文
405 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CottZheng 2016-08-04
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
那谁知道,你又没告诉我们对象的结构
            var s = File.ReadAllText("d7.txt");
            var a = JObject.Parse(s);
            for (var i = 0; i < a["geometries"].Count(); i++)
            {
                Console.WriteLine("x={0} y={1}", a["geometries"][i]["coordinates"][0], a["geometries"][i]["coordinates"][1]);
            }
明白了,谢谢!
我叫小菜菜 2016-08-04
  • 打赏
  • 举报
回复
标准的json,直接转换不就OK了嘛。
xuzuning 2016-08-04
  • 打赏
  • 举报
回复
那谁知道,你又没告诉我们对象的结构
            var s = File.ReadAllText("d7.txt");
var a = JObject.Parse(s);
for (var i = 0; i < a["geometries"].Count(); i++)
{
Console.WriteLine("x={0} y={1}", a["geometries"][i]["coordinates"][0], a["geometries"][i]["coordinates"][1]);
}

CottZheng 2016-08-04
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
dy.geometries[i].coordinates[0] dy.geometries[i].coordinates[1] i = 0,1,2,3...n
“System.Collections.Generic.Dictionary<string,object>”未包含“coordinates”的定义,是什么情况?
xuzuning 2016-08-04
  • 打赏
  • 举报
回复
dy.geometries[i].coordinates[0] dy.geometries[i].coordinates[1] i = 0,1,2,3...n

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧