How to parse JSON from Gmail API using JavaScript?

后端 未结 2 942
旧时难觅i
旧时难觅i 2020-12-20 09:20

Using JavaScript, how do I extract the Date, To, From, Subject and Text fields from the Gmail API\'s return (see below)?

It\'s not in the usual name-value pair, at l

相关标签:
2条回答
  • 2020-12-20 10:08

    Surfing on the Internet I have found this class which describes a Generic GMail Message. You might use this to easily parse the JSON (by using any of the wide range of provided libraries).

    0 讨论(0)
  • 2020-12-20 10:20

    you can use e.g. filter function as follows:

    var extractField = function(json, fieldName) {
      return json.payload.headers.filter(function(header) {
        return header.name === fieldName;
      })[0];
    };
    var date = extractField(response, "Date");
    var subject = extractField(response, "Subject");
    

    Does this help?

    0 讨论(0)
提交回复
热议问题