【问题标题】:How to get the json message from local using xamarin cross platform development如何使用xamarin跨平台开发从本地获取json消息
【发布时间】:2016-06-21 20:16:00
【问题描述】:

如何使用xamarin跨平台开发从本地如sampledata.json获取json数据。

【问题讨论】:

  • 来自应用程序文件夹?
  • 是的,应用文件夹有sampledata.json
  • egor-gromadskiy你的文章也有帮助

标签: android xamarin xamarin.forms


【解决方案1】:

无法添加评论。你研究过这个article吗?

【讨论】:

    【解决方案2】:

    试试这个:

    Type classType = typeof(Yourclassnamehere); 
    TypeInfo classTypeInfo = classType.GetTypeInfo();
    Assembly assemblyType = classTypeInfo.Assembly;
    System.IO.Stream stream = assemblyType.GetManifestResourceStream(classType.Namespace + ".sampledata.json");
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    string json = sr.ReadToEnd();
    

    【讨论】:

    • ` #region 如何加载 Json 文件嵌入的资源 var assembly = typeof(LoadResourceJson).GetTypeInfo().Assembly;流流 = assembly.GetManifestResourceStream("WorkingWithFiles.PCLJsonResource.json");雇员[]雇员;使用 (var reader = new System.IO.StreamReader(stream)) { var json = reader.ReadToEnd(); var rootobject = JsonConvert.DeserializeObject(json);员工 = rootobject.Employees; } #endregion var listView = new ListView(); listView.ItemsSource = 员工; `
    • System.ArgumentNullException:值不能为空。参数名称:stream this as error
    猜你喜欢
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    相关资源
    最近更新 更多