0

I am trying very hard and losing my patience with trying to send a simple array across to tabris.js

using this ws.send(JSON.stringify(["friendArray",{data: results}])) i have to stringify it or it just crashes my tabris app for no reason but when i go to JSON.parse() it. it keeps just giveing me an error Unexpected token 1 in JSON at psotion 0

I'm honestly at a loss I don't know what I could be doing wrong it could be something super simple but I'm frying my brain just trying to come up with a way to transport this simple information could someone please point me in the right direction

Nik Hendricks
  • 244
  • 2
  • 6
  • 29
  • 1
    Check the device logs (iOS) or logcat (Android) for the exact reason of the crash. – Cookie Guru Nov 19 '19 at 05:50
  • 1
    Can you try logging out the data before passing it to `JSON.parse` to see exactly what you're getting back? – Cookie Guru Nov 19 '19 at 05:50
  • when i `console.log(message.data)` this is what i get `'["friendArray",{"data":[{"username":"Tim","uid":"twq1jiy8k34r06m5"},{"username":"dillon","uid":"1fhbe39ok323irwy"}]}]'` – Nik Hendricks Nov 19 '19 at 06:00

1 Answers1

1

try something like, I assume results is some kind of variable, you just need to put data key in double quotes.

JSON.stringify(["friendArray",{data: results}])

to -

JSON.stringify(["friendArray",{"data": results}])
Abhishek
  • 1,543
  • 3
  • 13
  • 29
  • well results is actually an array with objects inside – Nik Hendricks Nov 19 '19 at 05:56
  • there is quite a big possibility that I am quite dumb at some times and I'm embarrassed to admit that `JSON.parse()` was doing exactly what I needed it to but I was parsing all socket messages and I forgot to convert my login true message to use json so it always just failed right when i logged in – Nik Hendricks Nov 19 '19 at 06:17
  • 1
    I am still not sure what exactly you want to perform, by theway I think syntax provided above is correct as per question. – Abhishek Nov 19 '19 at 06:23
  • 2
    your syntax did help me but the root of the problem was me trying to parse something that was not being returned as JSON I converted all the socket events to return JSON and now it's working – Nik Hendricks Nov 19 '19 at 06:24