Google脚本json解析问题

问题描述 投票:0回答:1

我使用此代码来解析我的网络请求响应:

for (var [key,val] of Object.entries(jsonObj)) {
  console.log("Key="+key); 
  console.log("Value="+val);
}

它适用于我的一个网址,但对于我得到的另一个网址:

{members=[Ljava.lang.Object;@3e0dc74, list_id=xxxxx, total_items=2.0, _links=[Ljava.lang.Object;@610c2a56}

响应没问题,但 json.parse() 让它变得很糟糕...成员列表不是假设的列表,而是 Ljava 对象?

** 我看到响应就像 json 中的一个数组,不知道如何继续它 **

有什么想法吗? 谢谢!

回复在这里

{"members":[{"id":"14d4xd529edc51eac6c2","email_address":"[email protected]","unique_email_id":"421ccfc0de","contact_id":"56f0eb4b2034f1228b3ea76e5eac22c6","full_name":"www","web_id":522903574,"email_type":"html","status":"subscribed","consents_to_one_to_one_messaging":true,"merge_fields":{"FNAME":"www","LNAME":"eeee","ADDRESS":{"addr1":"22 du plaisir","addr2":"","city":"xxxxxx","state":"qc","zip":"xxxx","country":"US"},"PHONE":"","MMERGE6":"","MMERGE5":"","MMERGE9":"","MMERGE10":"","MMERGE7":"","MMERGE8":""},"interests":{"e539c5b413":true,"8b4b1cc4be":true,"ff755b6893":false,"e78e70c1ec":false,"7bb4f39707":false,"13fd433d6b":false,"d2c372d6d0":false,"8450588744":false,"461896449a":false,"d5514d2d0b":false,"5dfb9c860b":false,"5775586056":false,"d07314aaf0":false,"851b0ab3e5":false,"9323e42080":false,"5c00098a74":false,"19fcaa30f9":false,"534f03a40c":false,"bd85a86aae":false,"a5abdc2e42":false,"e7b4a3ada0":false,"970e155af0":false,"0569ab3c82":false,"09c995ef83":false,"de65267b73":false,"7dd7155626":false,"2adcefc913":false,"f87d68d423":false,"83d27bff8f":false,"934b62ae80":false,"ff41de7dff":false,"d70e507585":false,"08045c1b3d":false,"02a8543521":true,"c2a43803b1":false,"55d1bbb773":false,"27abb86269":false},"stats":{"avg_open_rate":0,"avg_click_rate":0,"ecommerce_data":{"total_revenue":0,"number_of_orders":0,"currency_code":"CAD"}},"ip_signup":"","timestamp_signup":"","ip_opt":"xx4.x2.1x.1xx","timestamp_opt":"2024-01-17T23:51:54+00:00","member_rating":2,"last_changed":"2024-01-31T13:57:04+00:00","language":"","vip":false,"email_client":"iPhone","location":{"latitude":0,"longitude":0,"gmtoff":0,"dstoff":0,"country_code":"","timezone":"","region":""},"source":"Admin Add","tags_count":0,"tags":[],"list_id":"fx3240b7","_links":[{"rel":"self","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"parent","href":"https:","method":"GET","targetSchema":"https:","schema":"https:"},{"rel":"update","href":"https:","method":"PATCH","targetSchema":"https:","schema":"https:"},{"rel":"upsert","href":"https:","method":"PUT","targetSchema":"https:","schema":"https:"},{"rel":"delete","href":"https:","method":"DELETE"},{"rel":"activity","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"goals","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"notes","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"events","href":"https:","method":"POST","targetSchema":"https:"},{"rel":"delete_permanent","href":"https:","method":"POST"}]},{"id":"be87b47fe6cebade61ced3fe638b13dc","email_address":"[email protected]","unique_email_id":"788b930fc5","contact_id":"0665a6462a9dfa2fd2350bbeecae45ff","full_name":"pat","web_id":522903562,"email_type":"html","status":"subscribed","consents_to_one_to_one_messaging":true,"merge_fields":{"FNAME":"pat","LNAME":"laf","ADDRESS":{"addr1":"20 du saint-\u00e9milion","addr2":"","city":"bcccam","state":"qc","zip":"ccc","country":"CA"},"PHONE":"","MMERGE6":"","MMERGE5":"","MMERGE9":"","MMERGE10":"","MMERGE7":"","MMERGE8":""},"interests":{"e539c5b413":true,"8b4b1cc4be":false,"ff755b6893":false,"e78e70c1ec":false,"7bb4f39707":false,"13fd433d6b":false,"d2c372d6d0":false,"8450588744":false,"461896449a":false,"d5514d2d0b":false,"5dfb9c860b":false,"5775586056":false,"d07314aaf0":false,"851b0ab3e5":false,"9323e42080":false,"5c00098a74":false,"19fcaa30f9":false,"534f03a40c":false,"bd85a86aae":false,"a5abdc2e42":false,"e7b4a3ada0":false,"970e155af0":false,"0569ab3c82":false,"09c995ef83":false,"de65267b73":false,"7dd7155626":false,"2adcefc913":false,"f87d68d423":false,"83d27bff8f":false,"934b62ae80":false,"ff41de7dff":false,"d70e507585":false,"08045c1b3d":false,"02a8543521":false,"c2a43803b1":false,"55d1bbb773":false,"27abb86269":false},"stats":{"avg_open_rate":0,"avg_click_rate":0,"ecommerce_data":{"total_revenue":0,"number_of_orders":0,"currency_code":"CAD"}},"ip_signup":"","timestamp_signup":"","ip_opt":"xx.9x.1xx.1xx","timestamp_opt":"2024-01-17T23:50:35+00:00","member_rating":2,"last_changed":"2024-01-26T16:03:04+00:00","language":"","vip":false,"email_client":"","location":{"latitude":29.46,"longitude":-98.57,"gmtoff":-6,"dstoff":-5,"country_code":"US","timezone":"america/chicago","region":"tx"},"source":"Admin Add","tags_count":0,"tags":[],"list_id":"fcc73240b7","_links":[{"rel":"self","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"parent","href":"https:","method":"GET","targetSchema":"https:","schema":"https:"},{"rel":"update","href":"https:","method":"PATCH","targetSchema":"https:","schema":"https:"},{"rel":"upsert","href":"https:","method":"PUT","targetSchema":"https:","schema":"https:"},{"rel":"delete","href":"https:","method":"DELETE"},{"rel":"activity","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"goals","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"notes","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"events","href":"https:","method":"POST","targetSchema":"https:"},{"rel":"delete_permanent","href":"https:","method":"POST"}]}],"list_id":"fcc73240b7","total_items":2,"_links":[{"rel":"self","href":"https:","method":"GET","targetSchema":"https:","schema":"https:"},{"rel":"parent","href":"https:","method":"GET","targetSchema":"https:"},{"rel":"create","href":"https:","method":"POST","targetSchema":"https:","schema":"https:"}]}
json google-sheets google-apps-script webrequest urlfetch
1个回答
0
投票

如果您只需要从您提供的结构中导出电子邮件,您可以使用此功能:

// This function is only to demonstrate how the extraction works
// Assumes that there is a variable `payload` - already parsed JSON
function example() {
  console.log(extractEmails(payload))
}

// Extract emails
function extractEmails(payload) {
  return payload.members.map(member => 
    member.email_address
  )
}
© www.soinside.com 2019 - 2024. All rights reserved.