0

I am new to android & using android studio.

i have put test.json file in C:\inetpub\wwwroot of the localhost on my computer.

  1. How to simply connect to the local host from my android studio application?
  2. How to fetch the file into a json object in my application so i could parse it?

Thank you.

  • 1
    If it is a static JSON document then put it into your `assets` folder and load it from the filesystem. http://stackoverflow.com/questions/9544737/read-file-from-assets – Cody Caughlan Dec 22 '15 at 18:38

1 Answers1

0

get localhost and the android device on the same wireless subnet

example

laptop 192.168.1.158

phone 192.168.1.166

start the webserver on laptop where wwwroot is root

use preferred http package for android ( okhttp , volley, httpurlconnection ... )

in the 'whenDone' or std Callback slot , just create a JSON obj from the http.response.readStream ....

JsonNode root = new ObjectMapper().readValue(new ByteArrayInputStream(response), JsonNode.class);

        roleUserMp = new HashMap<String, ArrayList<String>>();
        String mRoleId, mRoleName;
        ArrayNode array = (ArrayNode) root.path("results");
        for(JsonNode node :  array){
//       if(Trace.debug)Log.d(TAG, "getListRole " +node.path("name").getTextValue() );
            role_arr.add(node.path("name").getTextValue());
            mRoleName = node.path("name").getTextValue();
            mRoleId = node.path("objectId").getTextValue();
            getUserRelations(mRoleId, mRoleName); //mapEntry "roleNm" :[userid, us2, us3...]
        }
Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43