Client:
using UnityEngine;using System.Collections;using LitJson;public class GetPhotoList : MonoBehaviour { // Use this for initialization void Start () { StartCoroutine(GetPhotos()); } // Update is called once per frame IEnumerator GetPhotos(){ WWWForm form = new WWWForm(); form.AddField("id","123"); WWW w = new WWW("http://localhost:36944/GetPhotoList.ashx",form); while (!w.isDone){yield return new WaitForEndOfFrame();} if (w.error != null){Debug.LogError(w.error);} Debug.Log(w.text); JsonData jd = JsonMapper.ToObject(w.text); for (int i = 0; i < jd.Count; i++) { Debug.Log("id=" + jd[i]["id"]); Debug.Log("name=" + jd[i]["name"]); } }}
Server:
Using System; using System. collections. generic; using System. linq; using System. web; using System. runtime. serialization. json; using System. serviceModel; using System. serviceModel. web; using System. IO; namespace UpdatePhoto {/// <summary> // summary of GetPhotoList /// </summary> public class GetPhotoList: IHttpHandler {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/pla In "; string id = context. request. form ["id"]; string path = context. request. physicalApplicationPath; // context. response. write ("Hello World"); List <Photo> photos = GetPhotos (id, path); DataContractJsonSerializer djson = new DataContractJsonSerializer (photos. getType (); djson. writeObject (context. response. outputStream, photos);} public List <Photo> GetPhotos (string id, string path) {// get the directory string local Path = path + id + "\"; // read the file in the directory if (! Directory. exists (localPath) return null; string [] files = Directory. getFiles (localPath); List <Photo> photos = new List <Photo> (); foreach (string file in files) {string filename = file. substring (file. lastIndexOf ('\') + 1); Photo p = new Photo (); p. name = filename; p. id = id; photos. add (p) ;}return photos ;}public bool IsReusable {get {return false ;}} public class Photo {public string id; public string name ;}}