Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

android - JSONString won't convert to JSONArray

I am attempting to send a string json of teams through Bluetooth to another android device. For some reason the Serializer will load a small list of teams but a large list of teams causes this error:

01-21 13:21:30.584    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Unterminated string at character 990 of [{"teleStackDirection":0,"teleCoopSet":0,"autoTotes":0,"teleCoopStack":0,"autoProgs":0,"telePlatform":0,"teleStackTotes":0,"mechLitterPusher":false,"mechLitterInserter":false,"teamNum":0,"mechToteFeeder":false,"teleCarryTote":0,"autoPos":0,"autoMoveTote":false,"mechContainerFlipper":false,"teleHumanStation":0,"id":"6d1d1c80-d386-401c-91c7-3260fdb28a9b","autoMove":false,"telePickUpLitter":false,"autoContainers":0,"teleMoveLitter":false,"teleStackContainers":0,"mechContainerStepRemover":false,"telePlaceTote":0,"telePlaceLitter":0},{"teleStackDirection":0,"teleCoopSet":0,"autoTotes":0,"teleCoopStack":0,"autoProgs":0,"telePlatform":0,"teleStackTotes":0,"mechLitterPusher":false,"mechLitterInserter":false,"teamNum":1,"mechToteFeeder":false,"teleCarryTote":0,"autoPos":0,"autoMoveTote":false,"mechContainerFlipper":false,"teleHumanStation":0,"id":"e10f158f-7254-4bfb-85eb-eb402be790c3","autoMove":false,"telePickUpLitter":false,"autoContainers":0,"teleMoveLitter":false,"teleStackContain
    01-21 13:21:30.618    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value toPos" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.648    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value kContainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.656    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value lse of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.662    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value e of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.728    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value gs" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.734    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value gs" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.740    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value {"teleCoopSet":0,"teleStackDirection":0,"autoTotes":0,"autoProgs":0,"teleCoopStack":0,"mechLitterPusher":false,"teleStackTotes":0,"telePlatform":0,"mechLitterInserter":false,"teamNum":34,"mechToteFeeder":false,"autoMoveTote":false,"autoPos":0,"teleCarryTote":0,"mechContainerFlipper":false,"teleHumanStation":0,"id":"c2108315-2ea6-4cd5-8205-c845ae48739c","autoMove":false,"autoContainers":0,"telePickUpLitter":false,"teleStackContainers":0,"teleMoveLitter":false,"mechContainerStepRemover":false,"telePlaceLitter":0,"telePlaceTote":0} of type org.json.JSONObject cannot be converted to JSONArray
    01-21 13:21:30.757    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value {"teleCoopSet":0,"teleStackDirection":0,"autoTotes":0,"autoProgs":0,"teleCoopStack":0,"mechLitterPusher":false,"teleStackTotes":0,"telePlatform":0,"mechLitterInserter":false,"teamNum":34,"mechToteFeeder":false,"autoMoveTote":false,"autoPos":0,"teleCarryTote":0,"mechContainerFlipper":false,"teleHumanStation":0,"id":"c2108315-2ea6-4cd5-8205-c845ae48739c","autoMove":false,"autoContainers":0,"telePickUpLitter":false,"teleStackContainers":0,"teleMoveLitter":false,"mechContainerStepRemover":false,"telePlaceLitter":0,"telePlaceTote":0} of type org.json.JSONObject cannot be converted to JSONArray
    01-21 13:21:30.775    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value {"teleCoopSet":0,"teleStackDirection":0,"autoTotes":0,"autoProgs":0,"teleCoopStack":0,"mechLitterPusher":false,"teleStackTotes":0,"telePlatform":0,"mechLitterInserter":false,"teamNum":34,"mechToteFeeder":false,"autoMoveTote":false,"autoPos":0,"teleCarryTote":0,"mechContainerFlipper":false,"teleHumanStation":0,"id":"c2108315-2ea6-4cd5-8205-c845ae48739c","autoMove":false,"autoContainers":0,"telePickUpLitter":false,"teleStackContainers":0,"teleMoveLitter":false,"mechContainerStepRemover":false,"telePlaceLitter":0,"telePlaceTote":0} of type org.json.JSONObject cannot be converted to JSONArray
    01-21 13:21:30.777    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value ners" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.781    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value lePickUpLitter" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.787    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value HumanStation" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.794    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value CarryTote" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.801    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value sher" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.807    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value teleCoopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.866    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value chToteFeeder" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.873    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value ackTotes" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.879    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopSet" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.886    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value ver" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.894    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.900    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.904    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.905    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.908    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.909    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.911    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.912    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.914    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.915    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.916    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value tainers" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.958    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value eStackDirection" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.967    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value kUpLitter" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.974    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value Tote" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.981    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.988    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.992    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.994    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:30.995    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value oopStack" of type java.lang.String cannot be converted to JSONArray
    01-21 13:21:31.042    9596-9596/org.huntingtonrobotics.frcrecyclerushpitscouter D/FRCRecycleRushPitScouterJSONSerializer﹕ Error: org.json.JSONException: Value Flipper" of type java.lang.String c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem appears to be that your data is getting chunked, and you are trying to parse those chunks individually.

There are number of ways to approach this problem. One easy way would be to use ObjectInputStream and ObjectOutputStream instead of plain InputStream and OutputStream. The Object stream variants will handle ensuring that you are sending and receiving complete objects, so if you send a String in an output stream, you should get the complete stream back on the other side in the input stream.

Assuming you are sending the JSON as a String (and it is UTF-8 encoded), sending the JSON is as easy as calling writeUTF(String), then reading it using readUTF().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...