0

I've got a Socket coming back with this JSON from a camera

      var string:String = socket.readUTFBytes(socket.bytesAvailable);

      string = '{"rval":0,"msg_id":514}{ "msg_id": 7, "type": "video_record_complete" ,"param":"/tmp/fuse_d/DCIM/100MEDIA/YDXJ0149.mp4"}';

i.e. 2 JSON objects in the socket.

Is there any way to split them before decoding?

This is the JSON decode error I get when I try and decode them

JSONParseError: Unexpected characters left in input stream 

1 Answer 1

1

Is there any way to split them before decoding?

Sure, just use split():

var strings:Array = string.split("}{");

However, you can probably just extract each JSON message one at a time using readtUTF() instead of readtUTFBytes() with all bytesAvailable:

while (socket.bytesAvailable) {
    var json:String = socket.readUTF();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.