示例#1
0
        public async Task <Model.Recipef2f> getRecipe(String recipeId)
        {
            var httpClient = new HttpClient();
            var uri        = new Uri(stringUri + recipeId);

            HttpResponseMessage result = await httpClient.GetAsync(uri);

            Model.Recipef2f recipe = new Model.Recipef2f();

            JsonObject jsonObject = JsonObject.Parse(result.Content.ToString());

            JsonObject jsonValue = jsonObject.GetNamedObject("recipe", new JsonObject());

            recipe.Publisher = jsonValue.GetNamedString("publisher", "");
            recipe.F2fUrl    = jsonValue.GetNamedString("f2f_url", "");
            JsonArray ingredientsArray = jsonValue.GetNamedArray("ingredients");

            foreach (JsonValue ingredient in ingredientsArray)
            {
                recipe.IngredientsList += ingredient.ToString() + " \n ";
            }
            recipe.SourceUrl    = jsonValue.GetNamedString("source_url", "");
            recipe.ImageUrl     = jsonValue.GetNamedString("image_url", "");
            recipe.SocialRank   = jsonValue.GetNamedNumber("social_rank", 0);
            recipe.PublisherUrl = jsonValue.GetNamedString("publisher_url", "");
            recipe.Title        = jsonValue.GetNamedString("title", "");
            recipe.RecipeId     = recipeId;

            return(recipe);
        }
示例#2
0
        public async Task<Model.Recipef2f> getRecipe(String recipeId)
        {
            var httpClient = new HttpClient();
            var uri = new Uri(stringUri+recipeId);

            HttpResponseMessage result = await httpClient.GetAsync(uri);

            Model.Recipef2f recipe = new Model.Recipef2f();

            JsonObject jsonObject = JsonObject.Parse(result.Content.ToString());

            JsonObject jsonValue = jsonObject.GetNamedObject("recipe", new JsonObject());
            
            recipe.Publisher = jsonValue.GetNamedString("publisher", "");
            recipe.F2fUrl = jsonValue.GetNamedString("f2f_url", "");
            JsonArray ingredientsArray = jsonValue.GetNamedArray("ingredients");
            foreach(JsonValue ingredient in ingredientsArray)
            {
                recipe.IngredientsList += ingredient.ToString() + " \n ";
            } 
            recipe.SourceUrl = jsonValue.GetNamedString("source_url", "");
            recipe.ImageUrl = jsonValue.GetNamedString("image_url", "");
            recipe.SocialRank = jsonValue.GetNamedNumber("social_rank", 0);
            recipe.PublisherUrl = jsonValue.GetNamedString("publisher_url", "");
            recipe.Title = jsonValue.GetNamedString("title", "");
            recipe.RecipeId = recipeId;

            return recipe;
        }