سؤال

Im using the code from the following tutorial:

http://cssgallery.info/advanced-titanium-tutorial-bonjour-networking/

but as this is 2 years old it doesn't seem to work 100% (guessing because of some api changes)

as far as i can tell its not working because it breaks when trying to parse a string as json

this bit:

var connection = bjnet(win.player.name, function(data){
    var json_data = JSON.parse(data);
    make_blob(json_data.player,json_data.coords);//this is just a function that makes the ...blobs!
});

for some reason it is having trouble parsing the following string as json:

data = {"coords":{"x":166,"y":443},"player":{"color":"#0f0","name":"green"}}

and i cant figure out why! ive confirmed its a string etc, but after trying all day to fix it myself ive now admitted defeat and hoping a genius out there can help me!

btw the above function is called in the "read" event listener for "Titanium.Network.TCPSocket"

Thanks for your time :)

هل كانت مفيدة؟

المحلول

ive fixed it! .. well not me but someone else on this thread: http://developer.appcelerator.com/question/126520/tcp-sockets-and-jsonparse

turns out the socket was adding an extra character to the data being sent that was not playing nice with the json parser

it works fine now

thanks for your help guys :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top