Following is the json file for customers: https://we4cs.myshopify.com/admin/customers.json
I have a html form that should get submitted and update the json file. How do i do it? Please advise.
Following is the json file that is customers.json
{"customers":[{"accepts_marketing":false,"orders_count":0,"addresses":[{"company":"test","city":"test","address1":"test","name":"test
test","zip":"56576","address2":"test","country_code":"AZ","country":"Azerbaijan","province_code":null,"phone":"54765765878","last_name":"test","province":"hgjghj","first_name":"test"}],"tags":"","id":51036842,"last_name":"test","note":null,"email":"test@test.com","first_name":"test","total_spent":"0.00"},{"accepts_marketing":false,"or开发者_JAVA技巧ders_count":0,"addresses":[{"company":"","city":"newark","address1":"23
smith","name":"gggggggggggggggg
hhhhhhhhhhhhhhhhhh","zip":"08786","address2":"","country_code":"US","country":"United
States","province_code":"NJ","phone":"","last_name":"hhhhhhhhhhhhhhhhhh","province":"New
Jersey","first_name":"gggggggggggggggg"}],"tags":"","id":49755872,"last_name":"hhhhhhhhhhhhhhhhhh","note":null,"email":"gregadkins2001@aol.com","first_name":"gggggggggggggggg","total_spent":"0.00"},{"accepts_marketing":false,"orders_count":0,"addresses":[{"company":"dsfsdf","city":"newark","address1":"12
dfsdf","name":"sdfsdf
sdfsdf","zip":"08876","address2":"","country_code":"US","country":"United
States","province_code":"NJ","phone":"","last_name":"sdfsdf","province":"New
Jersey","first_name":"sdfsdf"}],"tags":"","id":47565872,"last_name":"sdfsdf","note":null,"email":"sdfdfsdaf@aol.com","first_name":"sdfsdf","total_spent":"0.00"},{"accepts_marketing":true,"orders_count":0,"addresses":[{"company":"xcvxcvcx","city":"bridgewater","address1":"112
asdasd","name":"zxcxzcxz
cxvxcvxv","zip":"08875","address2":"asdasd","country_code":"US","country":"United
States","province_code":null,"phone":"323123123","last_name":"cxvxcvxv","province":"","first_name":"zxcxzcxz"},{"company":"xcvxcvcx","city":"bridgewater","address1":"112
asdasd","name":"zxcxzcxz
cxvxcvxv","zip":"08875","address2":"asdasd","country_code":"US","country":"United
States","province_code":"NJ","phone":"323123123","last_name":"cxvxcvxv","province":"New
Jersey","first_name":"zxcxzcxz"}],"tags":"","id":40799732,"last_name":"cxvxcvxv","note":"","email":"handful4me@aol.com","first_name":"zxcxzcxz","total_spent":"0.00"}]}
- Pick a server side programming language. PHP is popular in the budget world. ASP.NET is popular in the Microsoft world. Java is popular in the Enterprise world. I like Perl. Other options are available.
- Parse the incoming data. There are libraries that do this for almost any programming language you can name.
- Apply a file lock to the JSON file
- Parse the JSON using a library for whatever language you are using.
- Add the new data to the memory structure you've created
- Save the file
- Remove the lock
- Return an OK message to the client
That said, you would probably be better off generating the JSON on demand and using it only as a transport mechanism. A real database is almost always a better option for storage and manipulation.
Basic way of writing to a file, you need fopen
, fwrite
and of course, fclose
.
<?php
if($_POST['json'])
{
$open_json = fopen('json_file.json', 'w');
if($open_json)
{
if(fwrite($open_json, $_POST['json'] === FALSE)
{
die('failed to write to file');
}
fclose($open_json);
}
else
{
die('failed to open file');
}
}
?>
EDIT: Now that you've mentioned it's from an API, you cannot use this to write to an external server.
精彩评论