Dani Rubenstein Posted February 6, 2014 Posted February 6, 2014 hello to all. i want to use get url to get json data from a php file. when i run a script i get 3 rows in json. {"id":"2","userID":"1","app":"1","from_name":"danirub","from_email":"[email protected]","reply_to":"[email protected]","title":"test","plain_text":"","html_text":null,"sent":"1391675943","to_send":"5","to_send_lists":"3","recipients":"5","timeout_check":null,"opens":null,"wysiwyg":"0","send_date":null,"lists":null,"timezone":null,"errors":null,"bounce_setup":"0","complaint_setup":"0"},{"id":"3","userID":"1","app":"1","from_name":"danirub","from_email":"[email protected]","reply_to":"[email protected]","title":"bbbb","plain_text":"","html_text":" how can i split the result it to 2 or more records ? Thanks Dani
doughemi Posted February 6, 2014 Posted February 6, 2014 Create a global field g.allfields. Script: Set Variable[$jsonSplit; YourJsonField] # delete commas between braces Set Variable [$jsonSplit; Substitute($jsonSplit; "},{" ; "}{" )] # delete open braces Set Variable [$jsonSplit; Substitute ($jsonSplit; "{" ; "" )] # change close braces to pilcrow to make list Set Variable [$jsonSplit; Substitute[$jsonSplit; "}" ; "¶" )] # count number of records to be made Set Variable [$recordCount ; ValueCount($jsonSplit)] # create records Loop New Record/Request Set Field [ g.allfields; GetValue($jsonSplit; $recordCount)] Set Variable [$recordCount; $recordCount - 1] # # using the same technique of creating value lists # (this time converting the commas into pilcrows), # parse the name-value pairs in g.allfields # into field names and values. # Exit Loop If [ $recordCount = 0]
comment Posted February 6, 2014 Posted February 6, 2014 Create a global field g.allfields. ... Loop New Record/Request Set Field [ g.allfields; GetValue($jsonSplit; $recordCount)] Set Variable [$recordCount; $recordCount - 1] ... You are creating a new record and setting a global field to the record's group of values?
doughemi Posted February 6, 2014 Posted February 6, 2014 You're right, of course; it should NOT be global. I originally was thinking that I needed a global field to store the whole json, before I realized that it could be stored in a variable. Then I didn't delete the word "global" from the post.
Dani Rubenstein Posted February 6, 2014 Author Posted February 6, 2014 Thanks very much. bus some there in not working right. can you have a lock @ the file please ? json.fmp12.zip
doughemi Posted February 6, 2014 Posted February 6, 2014 The JSON in field "a" has two object_name arrays, each of which contains 6 id arrays. Each id array has different name-value pairs. You did not indicate the object_name arrays in your original post. Exactly what do you wish to have in each record?
doughemi Posted February 6, 2014 Posted February 6, 2014 A couple more questions: 1. Does your real-world json always include two identical object_name arrays as your sample indicates? 2. Your sample data shows that userID and to_send are identical for each id. Is this the case in your real data?
Dani Rubenstein Posted February 6, 2014 Author Posted February 6, 2014 1.yes 2. it is only a test the data will change Thanks
Dani Rubenstein Posted February 9, 2014 Author Posted February 9, 2014 Ageing thanks for the help. I suck with Substitute i am trying to insert data to fields but with no success. ho do i do it ? like to insert the data of "from_email" and "to_send"
Recommended Posts
This topic is 3939 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now