Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 1.加载指定路径的文件
- * 2.读取文件的内容
- * 3.把 json 转化为对象(用到了第三方库 Newtonsoft.Json )
- **/
- public async Task<IList<RecipeGroup>> GetRecipeGroups()
- {
- // Read RecipeData.json from this PCL's DataModel folder
- var name = typeof(RecipeService).AssemblyQualifiedName.Split(',')[1].Trim();
- var assembly = Assembly.Load(new AssemblyName(name));
- var stream = assembly.GetManifestResourceStream(name + ".Data.RecipeData.json");
- // Parse the JSON and generate a collection of RecipeGroup objects
- using (var reader = new StreamReader(stream))
- {
- string json = await reader.ReadToEndAsync();
- var obj = new { Groups = new List<RecipeGroup>() };
- var result = JsonConvert.DeserializeAnonymousType(json, obj);
- return result.Groups;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement