I get a JSON string from a File like this:
"[ { "id": "eVgoHOU0000000011", "network": { "networkName": "EVgo" }, "status": "Available", "plugscore": 9, "stationname": "Wholefoods Market", "description": "Very dependable station next to store.", "location": { "latitude": 30.596481, "longitude": -96.353554, "address": { "address1": "Golden Acres", "address2": "second floor", "city": "College Station", "state": "TX", "zipcode": "77029" }, "description": "Map marker location is next to gas station." }, "connectors": [ { "type": "US Wall Outlet", "power": "40 amp", "status": "Uknown" }, { "type": "US Wall Outlet", "power": "40 amp", "status": "Uknown" }, { "type": "CHAdeMO", "power": "40 amp", "status": "Unavailable" } ], "planName": "No Charge to Charge" }]"
I'd like to convert it to a JSONArray like this:
Scanner scanner = new Scanner(file);
String json = scanner.useDelimiter("\\A").next();
JSONArray array = new JSONArray(json);`
However, the array object is always null. What is wrong here?
UPDATE Works correctly in my Android code when I use this:
Scanner scanner = new Scanner( context.getResources().openRawResource(R.raw.radar_search));
But it isn't working when I create my previous scanner from a File. There must be something that the Android framework is doing correctly that Java isn't...
UPDATE 2 I have been able to isolate the problem. It happens when I'm doing white-box testing of my Android application with Junit4. So, I am constructing this new object class which has this helper method to create a JSONArray, and it doesn't get created during the junit run. It gets created fine, though, in regular java code runtime.
array = {JSONArray@902} "null"