我制作的应用程序从服务器检索JSON文件,以便在地图上找到标记。我的问题是我从服务器检索的JSON文件有多个根元素。
这是JSON文件的示例。
{"class":"VERSION","release":"3.11","rev":"3.11-3","proto_major":3,"proto_minor":9}
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyUSB0","driver":"NMEA0183","activated":"2017-03-25T20:20:20.649Z","flags":1,"native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]}
{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}
{"class":"TPV","tag":"RMC","device":"/dev/ttyUSB0","mode":3,"time":"2017-03-25T20:20:21.000Z","ept":0.005,"lat":18.487301667,"lon":-69.942863333,"alt":73.300,"epx":3.788,"epy":3.496,"epv":6.612,"track":352.7300,"speed":0.010,"climb":-0.100,"eps":7.58,"epc":13.22}
因为我没有处理服务器,也没有将带有信息的JSON文件装到服务器上。 有没有办法处理这个文件?以及如何?我知道它不是有效的JSON格式。 有没有办法只在Android上的应用程序中读取TPV类?以及如何?& 是否可以在AsyncTask上执行此操作?
答案 0 :(得分:0)
你可以添加[到字符串的开头和a]结束并将其视为JsonArray。