如何在客户端保存JSON文件并在以后检索它?

Using PHP, I want to create a JSON file with say firstname, lastname.

After I use json_encode, how can I save it to the client and most importantly, how do I retrieve it and read it?

Use local storage

Or you could simply store the information in a cookie, but that may raise security issues. Plus you'd be sending that data back and forth on each request on your domain (html, css, images, etc.) which can slow down website performance.

If you need to just populate the auto-complete why do you need the file? Implement some RESTful api in the server-side that outputs a json and then consume the json in javascript using:

var JSONObject = eval('(' + data + ')');
alert(JSONObject.property1);

Here data is the json encoded string returned by the server-side.

If you really must save it to file, then I think cookies are the only option you have.