I am stuck on how to fix this problem, I think i understand the problem which is that the gson is in the incorrect format eg missing Bsid in this case. How would i fix it so if this problem so it doesnt happen again?
Error:E/AndroidRuntime: FATAL EXCEPTION: main
Process: , PID: 32171 com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 65536 path $[555].bBsid
Code Being Used:
if(json.length()== Integer.MAX_VALUE){
Log.d(TAG, "Error");
return null;
} else {
Log.i(TAG, json);
Type arrayType = new TypeToken<List<WifiObject>>() {
}.getType();
Gson gson = new Gson();
ArrayList<WifiObject> wifiObjectArrayList = new ArrayList<WifiObject>();
List wifiObjectList = gson.fromJson(json, arrayType);
for (int i = 0; i < wifiObjectList.size() - 1; i++) {
if (wifiObjectList.get(i) != null) {
WifiObject wifiObject = (WifiObject) wifiObjectList.get(i);
}
// Log.i(TAG, wifiObject.getBBSID());
// wifiObjectArrayList.add(wifiObject);
}
return wifiObjectArrayList;
}
Object:
public WifiObject(String bBSID, String sSID, String capabilites, Integer frequency, Integer level){
//Instead of this.bssid for example because the setters already have Log's in them
setBBSID(bBSID);
setSSID(sSID);
setCapabilites(capabilites);
setFrequency(Integer.toString(frequency));
setLevel(Integer.toString(level));
}
Trying to convert this:
02-28 23:57:53.876 4259-4259/ I/WifiHandler:
[{"bBsid":"00:62:ec:fd:ea:f0","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-45","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ea:f1","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-46","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ea:f2","capabilities":"[ESS]","frequency":"2462","level":"-46","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ea:f3","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"2462","level":"-46","sSid":"PLOCAL"},{"bBsid":"00:62:ec:fd:ea:f4","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-46","sSid":"SLaMFT"},{"bBsid":"00:62:ec:fd:ea:50","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-53","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ea:ff","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5520","level":"-53","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ea:fd","capabilities":"[ESS]","frequency":"5520","level":"-53","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ea:53","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"2437","level":"-54","sSid":"PLOCAL"},{"bBsid":"00:62:ec:fd:ea:51","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-55","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ea:52","capabilities":"[ESS]","frequency":"2437","level":"-55","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ea:fb","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5520","level":"-55","sSid":"SLaMFT"},{"bBsid":"00:62:ec:fd:ea:54","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-55","sSid":"SLaMFT"},{"bBsid":"00:62:ec:fd:ea:5d","capabilities":"[ESS]","frequency":"5240","level":"-56","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ea:fe","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5520","level":"-56","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ea:5e","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5240","level":"-57","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ea:5c","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"5240","level":"-57","sSid":"PLOCAL"},{"bBsid":"00:62:ec:fd:ea:5f","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5240","level":"-58","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ea:5b","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"5240","level":"-58","sSid":"SLaMFT"},{"bBsid":"00:62:ec:fd:ea:fc","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"5520","level":"-58","sSid":"PLOCAL"},{"bBsid":"00:62:ec:fd:ec:30","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-59","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ee:61","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2412","level":"-59","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ee:62","capabilities":"[ESS]","frequency":"2412","level":"-59","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ee:64","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2412","level":"-59","sSid":"SLaMFT"},{"bBsid":"00:62:ec:fd:ec:31","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-60","sSid":"KINGSWAP"},{"bBsid":"00:62:ec:fd:ee:60","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2412","level":"-60","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ee:63","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"2412","level":"-60","sSid":"PLOCAL"},{"bBsid":"00:62:ec:fd:ec:32","capabilities":"[ESS]","frequency":"2437","level":"-60","sSid":"The Cloud"},{"bBsid":"00:62:ec:fd:ec:34","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2437","level":"-61","sSid":"SLaMFT"},{"bBsid":"00:42:68:a6:a6:41","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-62","sSid":"KINGSWAP"},{"bBsid":"00:42:68:a6:a6:42","capabilities":"[ESS]","frequency":"2462","level":"-62","sSid":"The Cloud"},{"bBsid":"00:42:68:a6:a6:43","capabilities":"[WPA2-EAP-CCMP][WPA-EAP-TKIP][ESS]","frequency":"2462","level":"-62","sSid":"PLOCAL"},{"bBsid":"00:42:68:a6:a6:44","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-62","sSid":"SLaMFT"},{"bBsid":"00:42:68:a6:a6:40","capabilities":"[WPA2-EAP-CCMP][ESS]","frequency":"2462","level":"-62","sSid":"eduroam"},{"bBsid":"00:62:ec:fd:ec:33","capabilities":"[WPA2-EAP
Let me clear this in shortly;
Gson gson = new Gson();
String json ="[{\"bBsid\":\"00:62:ec:fd:ea:f0\",\"capabilities\":\"[WPA2-EAP-CCMP][ESS]\",\"frequency\":\"2462\",\"level\":\"-45\",\"sSid\":\"eduroam\"}]"; // Your Json String
if (json.equalsIgnoreCase("")) {
return null;
}
YourClassName obj = gson.fromJson(json, YourClassName.class);
return obj;
Here, obj is Your Class Object, which is converted into Class Object, Print Log of it & Check it. Hope this will Help you.
Possible reason is that the Json string is truncated. Truncation might happen only when Log
prints it but I think that is not the the case now.
Namely, if you remove the last incomplete WifiObject
from the Json and add closing ]
it deserializes right, with 34 WifiObjects
.
You should trace the point where the Json is generated and see what happens in between. I have experienced this same issue but just can not remember what was the reason in my case (will get back if I find it).
I suspect that there is something like storing this long string in SharedPreferences
but you have not provided code for the Json generation and later manipulation so hard to say anything more specific.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.