03-13-2018 23:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-13-2018 23:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
When I try to run my app via the simulator, I get this:
[5:10:39 PM]SyntaxError: Unexpected token o in JSON at position 1 [5:10:39 PM]Uncaught SyntaxError: Unexpected token o in JSON at position 1
No file or line number is reported, which makes debugging a bit hard. I guess the problem is with some internal code (although I'm probably causing it). I've tried using 'console.log' to see where execution gets to, but it seems to get nowhere.
When I run the app on real devices, it's fine.
Does anyone have any tips about how to debug this?
Gondwana Software
Answered! Go to the Best Answer.

Accepted Solutions
03-26-2018 02:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



03-26-2018 02:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
When you say real hardware, are you testing on iOS or Android?
The issue is this: on line 51 you call this: settingsStorage.setItem('accountStatus',{'name':accountStatusMsg});
The second argument to setItem is expected to be a string, but you pass an object. What happens is that the object is changed into a string, and .toString() on an object is [object Object]. Your settings then tries to parse this as valid JSON and clearly, it isn't.
You can fix this by calling JSON.stringify before passing to setItem, but I'm curious if iOS or Android are differing in behaviour here for you.
03-14-2018 20:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-14-2018 20:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
After a long process of trial-and-error, I've isolated the problem down to this line in companion/index.js:
settingsStorage.setItem('accountStatus',{'name':'abc'});
...where the corresponding component is declared in settings/index.jsx like this:
<TextInput label="Status" placeholder="Not created." settingsKey="accountStatus" disabled="true" />
It works fine on real hardware, but not in the simulator 0.5.0. Perhaps a bug to investigate...
Gondwana Software

03-15-2018 09:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



03-15-2018 09:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Could you private message me an export of your project from Studio? We'll try to reproduce this issue and see what's going on. Thanks!
03-16-2018 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-16-2018 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Gondwana Software

03-25-2018 19:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-25-2018 19:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
This problem still occurs with simulator 0.5.2.
Gondwana Software

03-26-2018 02:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



03-26-2018 02:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
When you say real hardware, are you testing on iOS or Android?
The issue is this: on line 51 you call this: settingsStorage.setItem('accountStatus',{'name':accountStatusMsg});
The second argument to setItem is expected to be a string, but you pass an object. What happens is that the object is changed into a string, and .toString() on an object is [object Object]. Your settings then tries to parse this as valid JSON and clearly, it isn't.
You can fix this by calling JSON.stringify before passing to setItem, but I'm curious if iOS or Android are differing in behaviour here for you.
03-26-2018 12:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-26-2018 12:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Many thanks for the reply and explanation. The code works fine on Android hardware, so there's a difference in behaviour.
If the offending line is changed to the string 'abc' rather than an object, it still crashes the simulator from memory. But I'll check this later today, and investigate whether data type conversions help.
The SDK complains about the use of life-cycle code before it dies; I wouldn't have thought that this should cause the observed problem so I think it's a red herring, but I could be wrong.
Ta again!
Gondwana Software

03-26-2018 20:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


03-26-2018 20:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Liam, you were, of course, exactly right. JSON.stringify(...) fixed it.
FWIW, the companion on Android was perfectly happy without it. This is a bit surprising because I would have assumed that the code base was similar.
Many thanks for looking at this. Development is much faster and more flexible using the simulator. 🙂
Gondwana Software

03-27-2018 03:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



03-27-2018 03:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Glad to hear that worked! I'll raise the issue internally about inconsistency across platforms, thanks! 🙂

