C# 如何从另一个项目开始活动

C# 如何从另一个项目开始活动,c#,android,json,xamarin,windows-phone,C#,Android,Json,Xamarin,Windows Phone,我在安卓和windows phone的天气应用程序工作。因此,我在另一个项目中的“解析类”中的“Weather.Api(Portable)”中编写了公共代码。“Weather.Droid”用于Android ParsingClass的代码如下: public static string tempGlobal; public static string cityTextGlobal; private static string GovnoTemperature;

我在安卓和windows phone的天气应用程序工作。因此,我在另一个项目中的“解析类”中的“Weather.Api(Portable)”中编写了公共代码。“Weather.Droid”用于Android

ParsingClass的代码如下:

    public static string tempGlobal;
    public static string cityTextGlobal;
    private static string GovnoTemperature;

    public async  Task<string> dataByCity(string city)
    {
        var url = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&APPID="+AppID;

        //ТОРМОЗИТ ЗДЕСЬ / BRAKES HERE
        await FetchAsync(url);
        return city;
    }

    public async Task<double> Data_down(double lat, double lon)
    {

        var url = String.Format(
          "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=metric&APPID=" + AppID);

        //ТОРМОЗИТ ЗДЕСЬ / BRAKES HERE
        await FetchAsync(url);

        return lat;
    }

    public async Task<string> FetchAsync(string url)
    {
        string jsonString;

        using (var httpClient = new System.Net.Http.HttpClient())
        {
            var stream = await httpClient.GetStreamAsync(url);
            StreamReader reader = new StreamReader(stream);
            jsonString = reader.ReadToEnd();
        }

        var json = jsonString;

        JsonValue firstitem = json;
        var mydata = JObject.Parse(json);

        cityTextGlobal = (mydata["name"]).ToString();

        string GovnoData = (mydata["main"]).ToString();

        //spliting string
        string[] values = GovnoData.Split(',');
        for (int i = 0; i < values.Length; i++)
        {
            values[i] = values[i].Trim();
            if (i == 0)
            {
                //tempGlobal = values[i];
                GovnoTemperature = values[i];
            }
        }
        tempGlobal = null;
        foreach (char c in GovnoTemperature)
        {
            if (c == '.')
            {
                break;
            }
            if (c == '-' || char.IsDigit(c) == true || c == '.')
            {
                tempGlobal += c.ToString();
            }
        }

        return jsonString;
    }
}

public class Coord
{
    public double lon { get; set; }
    public double lat { get; set; }
}

public class Weather
{
    public int id { get; set; }
    public string main { get; set; }
    public string description { get; set; }
    public string icon { get; set; }
}

public class Main
{
    public double temp { get; set; }
    public int pressure { get; set; }
    public int humidity { get; set; }
    public int temp_min { get; set; }
    public int temp_max { get; set; }
}

public class Wind
{
    public double speed { get; set; }
    public double deg { get; set; }
}

public class Clouds
{
    public int all { get; set; }
}

public class Sys
{
    public int type { get; set; }
    public int id { get; set; }
    public double message { get; set; }
    public string country { get; set; }
    public int sunrise { get; set; }
    public int sunset { get; set; }
}

public class RootObject
{
    public Coord coord { get; set; }
    public List<Weather> weather { get; set; }
    public string @base { get; set; }
    public Main main { get; set; }
    public int visibility { get; set; }
    public Wind wind { get; set; }
    public Clouds clouds { get; set; }
    public int dt { get; set; }
    public Sys sys { get; set; }
    public int id { get; set; }
    public string name { get; set; }
    public int cod { get; set; }
}
公共静态字符串tempGlobal;
公共静态字符串citytextlobal;
专用静态字符串GovnoTemperature;
公共异步任务数据库城市(字符串城市)
{
变量url=”http://api.openweathermap.org/data/2.5/weather?q=“+city+”&units=metric&APPID=“+APPID;
//这里有制动器
等待获取异步(url);
回归城市;
}
公共异步任务数据关闭(双lat,双lon)
{
var url=String.Format(
"http://api.openweathermap.org/data/2.5/weather?lat=“+lat+”&lon=“+lon+”&units=metric&APPID=“+APPID”);
//这里有制动器
等待获取异步(url);
返回lat;
}
公共异步任务FetchAsync(字符串url)
{
字符串jsonString;
使用(var httpClient=new System.Net.Http.httpClient())
{
var stream=await httpClient.GetStreamAsync(url);
StreamReader=新的StreamReader(流);
jsonString=reader.ReadToEnd();
}
var json=jsonString;
JsonValue firstitem=json;
var mydata=JObject.Parse(json);
citytextlobal=(mydata[“name”]).ToString();
字符串GovnoData=(mydata[“main”]).ToString();
//拆分字符串
字符串[]值=GovnoData.Split(',');
for(int i=0;i