Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /**
  2. * 1.加载指定路径的文件
  3. * 2.读取文件的内容
  4. * 3.把 json 转化为对象(用到了第三方库 Newtonsoft.Json )
  5. **/
  6. public async Task<IList<RecipeGroup>> GetRecipeGroups()
  7. {
  8. // Read RecipeData.json from this PCL's DataModel folder
  9. var name = typeof(RecipeService).AssemblyQualifiedName.Split(',')[1].Trim();
  10. var assembly = Assembly.Load(new AssemblyName(name));
  11. var stream = assembly.GetManifestResourceStream(name + ".Data.RecipeData.json");
  12.  
  13. // Parse the JSON and generate a collection of RecipeGroup objects
  14. using (var reader = new StreamReader(stream))
  15. {
  16. string json = await reader.ReadToEndAsync();
  17. var obj = new { Groups = new List<RecipeGroup>() };
  18. var result = JsonConvert.DeserializeAnonymousType(json, obj);
  19. return result.Groups;
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement