我从这里复制了这个json解析脚本:https://fmhelp.filemaker.com/help/16/fmp/en/index.html#page/FMP_Help/json-functions.html#ww1155222
filemaker json解析脚本:
Set Variable [ $ProductCount ; Value:
ValueCount (
JSONListKeys ( $$JSON ; "bakery.product" )
) ]
Set Variable [ $i; Value: 0 ]
If [ $ProductCount > 0 ]
Loop
New Record/Request
Set Field [ Products::ID ;
JSONGetElement ( $$JSON ; "bakery.product[" & $i & "]id" ) ]
Set Field [ Products::Price ;
JSONGetElement ( $$JSON ; "bakery.product[" & $i & "]price" ) ]
Set Field [ Products::Stock ;
JSONGetElement ( $$JSON ; "bakery.product[" & $i & "]stock" ) ]
Commit Records/Requests [ With dialog: Off ]
Set Variable [ $i ; Value: $i + 1 ]
Exit Loop If [ $i ≥ $ProductCount ]
End Loop
End If
当我使用脚本调试器和数据查看器并逐步完成我的脚本时,它会像它应该的那样工作,直到它到达脚本的末尾。脚本完成后,它会将每个记录中的所有id字段设置为它运行的最后一个id字段。我无法弄清楚如何解析我的数据并将其分成不同的记录。
这是我的剧本:
Insert from URL [ Select; with dialog: Off ; $json; "web address"]
Set Variable [ $grievanceCount ; Value:
ValueCount (
JSONListKeys ( $json ; "submissions" )
) ]
Set Variable [ $i; Value: 0 ]
If [ $grievanceCount > 0 ]
Loop
New Record/Request
Set Field [ grievanceSubmissions::ID ;
JSONGetElement ( $json ; "submissions[" & $i & "]id" ) ]
Commit Records/Requests [ With dialog: Off ]
Set Variable [ $i ; Value: $i + 1 ]
Exit Loop If [ $i ≥ $grievanceCount ]
End Loop
End If
JSON:
{“提交”:[{“id”:“383694318”,“timestamp”:“2018-02-09 15:23:45”,“user_agent”:“Mozilla / 5.0(Windows NT 6.1; rv: 58.0)Gecko / 20100101 Firefox / 58.0“,”remote_addr“:”1.1.1.1“,”payment_status“:”“,”纬度“:”0“,”经度“:”0“,”读“:”1“ },{“id”:“397263244”,“timestamp”:“2018-04-02 11:02:53”,“user_agent”:“Mozilla / 5.0(iPhone; CPU iPhone OS 11_2_6,如Mac OS X)AppleWebKit / 604.5.6(KHTML,与Gecko一样)Version / 11.0 Mobile / 15D100 Safari / 604.1“,”remote_addr“:”1.1.1.1“,”payment_status“:”“,”纬度“:”0“,”经度“:” 0“,”读“:”1“},{”id“:”397578480“,”timestamp“:”2018-04-03 12:23:12“,”user_agent“:”Mozilla / 5.0(Linux; Android) 7.0; SAMSUNG SM-G935A Build / NRD90M)AppleWebKit / 537.36(KHTML,如Gecko)SamsungBrowser / 6.4 Chrome / 56.0.2924.87 Mobile Safari / 537.36“,”remote_addr“:”1.1.1.1“,”payment_status“:”“, “纬度”: “0”, “经度”: “0”, “读”: “0”}], “总”:3, “页”:1, “pretty_field_id”: “59493345”}