C# 已初始化)@IDANMOSHER您不能返回var,因为var表示字符串[]。如果您希望返回单个字符串,请查看我的UpdateEyes,但我仍然不知道如何将'var'分配给'string'。在哪一部分?var“is”是一个字符串,通过使用“var”是隐式类型

C# 已初始化)@IDANMOSHER您不能返回var,因为var表示字符串[]。如果您希望返回单个字符串,请查看我的UpdateEyes,但我仍然不知道如何将'var'分配给'string'。在哪一部分?var“is”是一个字符串,通过使用“var”是隐式类型,c#,json,class,C#,Json,Class,已初始化)@IDANMOSHER您不能返回var,因为var表示字符串[]。如果您希望返回单个字符串,请查看我的UpdateEyes,但我仍然不知道如何将'var'分配给'string'。在哪一部分?var“is”是一个字符串,通过使用“var”是隐式类型化的。您可以执行以下操作:字符串类型=类型[0];它取决于要在数组中返回的类型。好的,它的工作方式与您编写的“string type=types[0];”相同。非常感谢你,伙计! using System; using System.Colle


已初始化)@IDANMOSHER您不能返回var,因为var表示字符串[]。如果您希望返回单个字符串,请查看我的UpdateEyes,但我仍然不知道如何将'var'分配给'string'。在哪一部分?var“is”是一个字符串,通过使用“var”是隐式类型化的。您可以执行以下操作:字符串类型=类型[0];它取决于要在数组中返回的类型。好的,它的工作方式与您编写的“string type=types[0];”相同。非常感谢你,伙计!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Web.Script.Serialization;

using System.Web.Extensions;
// using System.Web.Script.Serialization.JavaScriptSerializer;

[WebService(Namespace = "http://idanmoshe.com/", Description = "Idans' web services")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]


public class NetroadsWebServices : System.Web.Services.WebService
{
    public NetroadsWebServices()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    [WebMethod (Description = "Get google type by coordinate (road, street etc.)")]
    public string getGoogleType(float latitude, float longitude)
    {
        string completeUrl = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&sensor=true";
        var jsonString = new WebClient().DownloadString(completeUrl);
        Console.WriteLine ("Complete URL: "+completeUrl);

        JavaScriptSerializer jsonParse = new JavaScriptSerializer();
        GoogleGeoCodeResponse getTypes = jsonParse.Deserialize<GoogleGeoCodeResponse>(jsonString);


        return jsonString;
    }
}

public class GoogleGeoCodeResponse
{

    public string status { get; set; }
    public results[] results { get; set; }

}

public class results
{
    public string formatted_address { get; set; }
    public geometry geometry { get; set; }
    public string[] types { get; set; }
    public address_component[] address_components { get; set; }
}

public class geometry
{
    public string location_type { get; set; }
    public location location { get; set; }
}

public class location
{
    public string lat { get; set; }
    public string lng { get; set; }
}

public class address_component
{
    public string long_name { get; set; }
    public string short_name { get; set; }
    public string[] types { get; set; }
}
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://idanmoshe.com/">{ "results" : [ { "address_components" : [ { "long_name" : "Al Ismaileya - Port Saeed", "short_name" : "Al Ismaileya - Port Saeed", "types" : [ "route" ] }, { "long_name" : "Qesm Awal Al Ganoub", "short_name" : "Qesm Awal Al Ganoub", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Port Said", "short_name" : "Port Said", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Egypt", "short_name" : "EG", "types" : [ "country", "political" ] } ], "formatted_address" : "Al Ismaileya - Port Saeed, Qesm Awal Al Ganoub, Port Said, Egypt", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.10762660, "lng" : 32.20366510 }, "southwest" : { "lat" : 31.01789770, "lng" : 32.20137170 } }, "location" : { "lat" : 31.06282650, "lng" : 32.20248240 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 31.10762660, "lng" : 32.20386738029149 }, "southwest" : { "lat" : 31.01789770, "lng" : 32.20116941970849 } } }, "types" : [ "route" ] }, { "address_components" : [ { "long_name" : "Qesm Awal Al Ganoub", "short_name" : "Qesm Awal Al Ganoub", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Port Said", "short_name" : "Port Said", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Egypt", "short_name" : "EG", "types" : [ "country", "political" ] } ], "formatted_address" : "Qesm Awal Al Ganoub, Port Said, Egypt", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.34955880, "lng" : 32.28690060 }, "southwest" : { "lat" : 31.01694570, "lng" : 32.05233060 } }, "location" : { "lat" : 31.12950940, "lng" : 32.22000650 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 31.34955880, "lng" : 32.28690060 }, "southwest" : { "lat" : 31.01694570, "lng" : 32.05233060 } } }, "types" : [ "administrative_area_level_2", "political" ] }, { "address_components" : [ { "long_name" : "Port Said", "short_name" : "Port Said", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Egypt", "short_name" : "EG", "types" : [ "country", "political" ] } ], "formatted_address" : "Port Said, Egypt", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.36418070, "lng" : 32.5629240 }, "southwest" : { "lat" : 30.88772540, "lng" : 32.05233060 } }, "location" : { "lat" : 31.07586060, "lng" : 32.26538870 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 31.36418070, "lng" : 32.5629240 }, "southwest" : { "lat" : 30.88772540, "lng" : 32.05233060 } } }, "types" : [ "administrative_area_level_1", "political" ] }, { "address_components" : [ { "long_name" : "Egypt", "short_name" : "EG", "types" : [ "country", "political" ] } ], "formatted_address" : "Egypt", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.6715350, "lng" : 36.89454460 }, "southwest" : { "lat" : 21.99999990, "lng" : 24.69677480 } }, "location" : { "lat" : 26.8205530, "lng" : 30.8024980 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 31.6715350, "lng" : 36.89454460 }, "southwest" : { "lat" : 21.99999990, "lng" : 24.69677480 } } }, "types" : [ "country", "political" ] } ], "status" : "OK" } </string>
foreach(var result in getTypes.results)
{
   foreach(var address_component in result.address_components)
   {
        var types = address_component.types;
   }
}
foreach(var type in types)
{
   // type is the string 
   Console.WriteLine(type);
}