我正在Zoho Creator中构建一个应用程序,该应用程序从外部成员数据库中检索信息。
我有一个GET请求,该请求检索一个人的成员身份。一个人可以具有多个成员身份,从而导致返回多个JSON对象,例如:
[
{
"id": 76397,
"membership_level_id": 395,
"start_date": "2019-03-04",
"end_date": "2020-03-03",
"state": "partial",
"created_at": "2019-01-07T19:13:16+1100",
"adult_members": [
{
"contact_id": 5389
}
],
"child_members": [],
"contact_id": 5389
},
{
"id": 8728,
"membership_level_id": 937,
"start_date": "2019-01-07",
"end_date": "2019-02-06",
"state": "expired",
"created_at": "2019-01-07T20:09:12+1100",
"adult_members": [
{
"contact_id": 5389
}
],
"child_members": [],
"contact_id": 5389
}
]
我想要实现的是,对于返回的每个成员身份(在上面的示例中,有两个),将创建Memberships
形式的记录。
在上述情况下,应该以{{1}}格式创建两个记录,并关联它们的键值对。
我尝试将JSON响应转换为Memberships
,但似乎无法提取信息。
关于我如何为响应中返回的每个成员身份以表格形式创建新记录的想法吗?
答案 0 :(得分:0)
尝试一下:
//considering member1 is my response data
member1 = {{"id":76397,"membership_level_id":395,"start_date":"2019-03-04","end_date":"2020-03-03","state":"partial","created_at":"2019-01-07T19:13:16+1100","adult_members":{{"contact_id":5389}},"child_members":{},"contact_id":5389},{"id":8728,"membership_level_id":937,"start_date":"2019-01-07","end_date":"2019-02-06","state":"expired","created_at":"2019-01-07T20:09:12+1100","adult_members":{{"contact_id":5389}},"child_members":{},"contact_id":5389}};
//convert response to, toJsonLsit()
rows = member1.toJSONList();
// iterate through any number of membership returned
for each row in rows
{
info row;
id = row.getJSON("id");
info "id is: " + id;
contactId = row.getJSON("contact_id");
info "contact id: " + contactId;
startDate = row.getJSON("start_date");
info "startDate: " + startDate;
endDate = row.getJSON("end_date");
info "endDate: " + endDate;
state = row.getJSON("state");
info "state: " + state;
insertingData = insert into Memberships_Form
[
Added_User=zoho.loginuser
Contact_Id=contactId
membership_id=id
Start_Date=startDate
End_Date=endDate
State = state
];
}