如何从Json文件添加模型属性的自定义错误消息?

时间:2017-03-26 11:34:10

标签: json asp.net-mvc localization

我将所有字符串存储在Json文件中以进行本地化。如下。

[
  {
    "Key": "screen",
    "Value": "Screen No"
  },
  {
    "Key": "go",
    "Value": "Go!"
  },
  {
    "Key": "titlehome",
    "Value": "Search Particular Screan"
  },
  {
    "Key": "home",
    "Value": "Home"
  }] 

那么如何在Model for data Notation中访问这些字符串 我创建一个静态函数Utils.value("screen")并返回该键的值。

1 个答案:

答案 0 :(得分:0)

Hi Nasimbahar,

    public class josnResult
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }

    var _listResult= Newtonsoft.Json.JsonConvert.DeserializeObject<List<josnResult>>(jsonValue);

    josnResult _josnResult = _listResult.Where(t => t.Key == "screen").FirstOrDefault();

    if (_josnResult != null)
    {
        var _val = _josnResult.Value;
    }