首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gmail联系人/反序列化包含电子邮件的json对象

Gmail联系人/反序列化包含电子邮件的json对象
EN

Stack Overflow用户
提问于 2017-03-17 16:23:59
回答 1查看 95关注 0票数 0

我想获得gmail联系人(实际上是电子邮件联系人),所以我在google控制台注册并获得了凭证,并且使用访问令牌获得了联系人。具有范围:

代码语言:javascript
复制
https://www.google.com/m8/feeds/ + https://www.googleapis.com/auth/contacts.readonly

并请求uri作为:

代码语言:javascript
复制
https://www.google.com/m8/feeds/contacts/default/full?alt=json

这给了我这样的结果:

代码语言:javascript
复制
{
      "version": "1.0",
      "encoding": "UTF-8",
      "feed": {
        "xmlns": "http://www.w3.org/2005/Atom",
        "xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
        "xmlns$batch": "http://schemas.google.com/gdata/batch",
        "xmlns$gd": "http://schemas.google.com/g/2005",
        "xmlns$gContact": "http://schemas.google.com/contact/2008",
        "id": {
          "$t": "xxx@test.ai"
        },
        "updated": {
          "$t": "2017-03-17T16:00:05.743Z"
        },
        "category": [
          {
            "scheme": "http://schemas.google.com/g/2005#kind",
            "term": "http://schemas.google.com/contact/2008#contact"
          }
        ],
        "title": {
          "type": "text",
          "$t": "xxx's Contacts"
        },
        "link": [
          {
            "rel": "alternate",
            "type": "text/html",
            "href": "http://www.google.com/"
          },
          {
            "rel": "http://schemas.google.com/g/2005#feed",
            "type": "application/atom+xml",
            "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full"
          },
          {
            "rel": "http://schemas.google.com/g/2005#post",
            "type": "application/atom+xml",
            "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full"
          },
          {
            "rel": "http://schemas.google.com/g/2005#batch",
            "type": "application/atom+xml",
            "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/batch"
          },
          {
            "rel": "self",
            "type": "application/atom+xml",
            "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full?alt=json&max-results=25"
          },
          {
            "rel": "next",
            "type": "application/atom+xml",
            "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full?alt=json&start-index=26&max-results=25"
          }
        ],
        "author": [
          {
            "name": {
              "$t": "xxx"
            },
            "email": {
              "$t": "xxx@test.ai"
            }
          }
        ],
        "generator": {
          "version": "1.0",
          "uri": "http://www.google.com/m8/feeds",
          "$t": "Contacts"
        },
        "openSearch$totalResults": {
          "$t": "32"
        },
        "openSearch$startIndex": {
          "$t": "1"
        },
        "openSearch$itemsPerPage": {
          "$t": "25"
        },
        "entry": [
          {
            "id": {
              "$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/ca1e0840ced5eb5"
            },
            "updated": {
              "$t": "2017-03-13T10:27:43.365Z"
            },
            "category": [
              {
                "scheme": "http://schemas.google.com/g/2005#kind",
                "term": "http://schemas.google.com/contact/2008#contact"
              }
            ],
            "title": {
              "type": "text",
              "$t": "Adam aaa"
            },
            "link": [
              {
                "rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
                "type": "image/*",
                "href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/ca1e0840ced5eb5/1B2M2Y8AsgTpgAmY7PhCfg"
              },
              {
                "rel": "self",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/ca1e0840ced5eb5"
              },
              {
                "rel": "edit",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/ca1e0840ced5eb5/1489400863365001"
              }
            ],
            "gd$email": [
              {
                "rel": "http://schemas.google.com/g/2005#other",
                "address": "adam@test.ai",
                "primary": "true"
              }
            ]
          },
          {
            "id": {
              "$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/d06991a8a601600"
            },
            "updated": {
              "$t": "2017-03-13T10:27:43.365Z"
            },
            "category": [
              {
                "scheme": "http://schemas.google.com/g/2005#kind",
                "term": "http://schemas.google.com/contact/2008#contact"
              }
            ],
            "title": {
              "type": "text",
              "$t": "Bailey Bob"
            },
            "link": [
              {
                "rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
                "type": "image/*",
                "href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/d06991a8a601600/1B2M2Y8AsgTpgAmY7PhCfg"
              },
              {
                "rel": "self",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/d06991a8a601600"
              },
              {
                "rel": "edit",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/d06991a8a601600/1489400863365001"
              }
            ],
            "gd$email": [
              {
                "rel": "http://schemas.google.com/g/2005#other",
                "address": "bailey@test.ai",
                "primary": "true"
              }
            ]
          },
          {
            "id": {
              "$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/e33f110891b26a2"
            },
            "updated": {
              "$t": "2017-03-13T10:27:43.365Z"
            },
            "category": [
              {
                "scheme": "http://schemas.google.com/g/2005#kind",
                "term": "http://schemas.google.com/contact/2008#contact"
              }
            ],
            "title": {
              "type": "text",
              "$t": "cathy Wales"
            },
            "link": [
              {
                "rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
                "type": "image/*",
                "href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/e33f110891b26a2/1B2M2Y8AsgTpgAmY7PhCfg"
              },
              {
                "rel": "self",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/e33f110891b26a2"
              },
              {
                "rel": "edit",
                "type": "application/atom+xml",
                "href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/e33f110891b26a2/1489400863365001"
              }
            ],
            "gd$email": [
              {
                "rel": "http://schemas.google.com/g/2005#other",
                "address": "cathy@test.ai",
                "primary": "true"
              }
            ]
          }
        ]
      }
    }

要么我需要一种更好的方法从gmail中获取电子邮件联系人,要么我需要一种将这个json反序列化为类的方法,我试图通过将这个json转换成C#来反序列化,但是没有成功。让我知道能做些什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-24 10:56:10

解决了我的问题,有时会出现'$t‘之类的实例,或者其中包含'$’的类似实例,当转换为C#类时,会导致无效的名称。要解决这个问题,添加dll引用'Newtonsoft.Json‘并创建一个类,使用名称空间作为’使用Newtonsoft.Json‘,并在每个属性中名称无效,如下所示;

代码语言:javascript
复制
public string __invalid_name__$t { get; set; }

添加Json属性,如下所示,并根据您的喜好更改名称:

代码语言:javascript
复制
[JsonProperty("$t")]
public string NameOfMyChoosing { get; set; }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42862543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档