2016-07-01 62 views
1

我想在android中創建一種JSON服務器,在我的應用中創建一些REST調用。我創建這個WebServer:NanoHTTPD服務器JSOn android

public class WebServer extends NanoHTTPD{ 

Context context; 

public WebServer(Context context){ 
    super(8080); 
    this.context = context; 

} 

@Override 
public Response serve(IHTTPSession session) { 

    String msg = "["; 
    int id = R.raw.frame_1; 
    for(int i = 0; i<10; i++) { 
     InputStreamReader inputStreamReader = new InputStreamReader(context.getResources().openRawResource(id + 1)); 
     BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 
     String line; 
     try { 
      while ((line = bufferedReader.readLine()) != null) { 
       msg += line; 
      } 
     } catch (IOException e) { 

     } 

     if(i != 9){ 
      msg += ","; 
     } 
    } 

    msg += "]"; 

    return new NanoHTTPD.Response(msg); 
} 

所以我創建了一個JSON數組。現在我想進行一些其他電話,如GET http://localhost/?frame_id=1,我該怎麼做?

回答

0

請你能以更準確的方式解釋你的目標。我想你想要得到休息uri,對吧,如果是這樣,session.getUri()將會工作