解析字段名称与JSON冒号 [英] Parsing field name with a colon in JSON

查看:469
本文介绍了解析字段名称与JSON冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何可以解析,如果JSON字段包含一个冒号(:)?像这样的:

How can we parse if json fields contains a colon(:)? Like this:

{
  "dc:creator":"Jordan, Micheal",
  "element:publicationName":"Applied Ergonomics",
  "element:issn":"2839749823"
}

其实我不知道如何与像restsharp库做到这一点,映射?

In fact I wonder how to do this with a library like restsharp, for mapping?

推荐答案

使用 Json.Net

string json = @"{
            ""dc:creator"":""Jordan, Micheal"",
            ""element:publicationName"":""Applied Ergonomics"",
            ""element:issn"":""2839749823""
        }";

var pub = JsonConvert.DeserializeObject<Publication>(json);


public class Publication
{
    [JsonProperty("dc:creator")]
    public string creator { set; get; }
    [JsonProperty("element:publicationName")]
    public string publicationName { set; get; }
    [JsonProperty("element:issn")]
    public string issn { set; get; }
}

Console.WriteLine(JObject.Parse(json)["dc:creator"]);

这篇关于解析字段名称与JSON冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆