C# 用C语言访问JSON数据#

C# 用C语言访问JSON数据#,c#,google-maps-api-3,json.net,C#,Google Maps Api 3,Json.net,我从下面的JSON返回中访问数字距离“值”的时间很长。我正在使用JSON.NET3.5库。该程序将在以下情况下终止: 编译器错误消息:CS0119:“System.Xml.Linq.Extensions.Elements(System.Collections.Generic.IEnumerable,System.Xml.Linq.XName)”是一个“方法”,在给定上下文中无效 源错误: Line 64: GeoElements Elements = JsonConvert.Deseri

我从下面的JSON返回中访问数字距离“值”的时间很长。我正在使用JSON.NET3.5库。该程序将在以下情况下终止:

编译器错误消息:CS0119:“System.Xml.Linq.Extensions.Elements(System.Collections.Generic.IEnumerable,System.Xml.Linq.XName)”是一个“方法”,在给定上下文中无效

源错误:

Line 64: GeoElements Elements =     JsonConvert.DeserializeObject<GeoElements>geoResponse.ToString());
Line 65: 
Line 66: count2 = geoResponse.Elements.Length;
Line 67: for (int j = 0; j < count2; j++)
Line 68: {

公共部分类映射路径:System.Web.UI.Page
{ 
公共类大地距离
{
公共字符串值{get;set;}
公共字符串文本{get;set;}
}
公共类地质要素
{
公共大地距离{get;set;}
}
公开课乔治索
{
公共地理元素[]元素{get;set;}
}         
公共类地理响应
{            
公共字符串状态{get;set;}
公共GeoResult[]行{get;set;}
} 
公共整数解析距离(字符串流)
{
//进程响应文件
georResponse georResponse=JsonConvert.DeserializeObject(流);
int-dist=0;
整数计数=0;
int count2=0;
尝试
{
如果(geoResponse.Status==“OK”)
{
计数=geoResponse.Rows.Length;
for(int i=0;i”);
Response.Write(“结果:+geoResponse.Rows.Length”);
回答。写(“
”); } 返回距离; }
元素是JSON中的数组,但类中只有一个值,使其成为数组应该可以工作:

public GeoElements[] elements { get; set; } 
反序列化类型必须是数组或实现集合接口,如IEnumerable、ICollection或IList

它完全按照tin上的说明执行:您需要一个
GeoElements
数组来反序列化JSON。 代码中的
GeoElement
是单个值。它是json中的数组。因此,要么继承
GeoElement
类中的
IList/ICollection
接口,要么将GeoElement声明为GeoElements数组

class GeoElement : ICollection { ... }


最终发现问题。我的类定义错误。我只需将从Google获取的JSON数据放入框中,它就为我生成了正确的类结构。

这消除了一个错误,给我留下了:CS1061:“System.Array”不包含“distance”的定义,也不包含“distance”的扩展方法无法找到“接受类型为“System.Array”的第一个参数(是否缺少using指令或程序集引用)?源错误:第61行:for(int i=0;ipublic GeoElements[] elements { get; set; }
class GeoElement : ICollection { ... }
GeoElement[] elements = JSONConverter.Deserialize(stream);