Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20053] JSON.parse not implemented on Windows Phone?

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2015-11-23T16:03:08.000+0000
Affected Version/sRelease 4.1.1
Fix Version/sn/a
ComponentsWindows
Labelsn/a
ReporterMarian Kucharcik
AssigneeChristopher Williams
Created2015-11-12T12:40:21.000+0000
Updated2015-11-23T16:03:08.000+0000

Description

Hi guys, I'm trying to parse simple JSON object loaded from web. On iOS it's working fine. On Android, I have to use eval('('+this.responseText+')'). But on Windows phone, JSON.parse does nothing(when I can choose JSON methods, parse method is only for mobile weband windows logo is grayed ) and eval() crash the app(without any error log). Can somebody please help me? Thank you.

Comments

  1. Marian Kucharcik 2015-11-12

    I tried to pack JSON.parse into try/catch and it gives me error: SyntaxError: JSON Parse error: Unrecognized token '?' The JSON itself is valid, I tried to parse it via console in browsers, even question mark ? is not present in that text. Thank you
  2. Christian Brousseau 2015-11-12

    Why do you have to use "eval" on Android specifically? If you can't even parse it without a hitch on Android, then there must be something _fishy _with your JSON data. Could you add the data to the ticket? That would give everyone a better understanding of your issue.
  3. Marian Kucharcik 2015-11-12

    Hi Christian, this is my JSON output from web:
       [{"title":"Výkopové práce v Humennom","perex":"V posledných týždňoch sa na mnohých miestach v Humennom realizovali aj stále realizujú výkopové práce, Park mieru nevynímajúc. Viacerí Humenčania sa zaujímali, čo je v tomto prípade vlastne za tým. Tu je objasnenie.","article_id":"6","created":"28.9.2015","file":"http:\/\/edu.mkreo.sk\/img\/article\/app\/vykopove-prace-v-humennom-14.jpg"},{"title":"Škola vo Sv. Antone bude mať rýchly internet, stavbu siete dnes kontroloval minister","perex":"Už len niekoľko desiatok metrov výkopu delí pracovníkov od školy vo Svätom Antone, aby ju pripojili prostredníctvom optickej siete na vysokorýchlostný internet.","article_id":"5","created":"11.9.2015","file":"http:\/\/edu.mkreo.sk\/img\/article\/app\/skola-vo-sv-antone-bude-mat-rychly-internet-stavbu-siete-dnes-kontroloval-minister-10.jpg"},{"title":"Projekt „Digitálne učivo na dosah“ zvýši kvalitu výučby na 200 školách v regiónoch Slovenska","perex":"Prístup k digitálnemu učivu garantovanou rýchlosťou, bezplatný technický servis aj zvýšenú bezpečnosť – to všetko prinesie do 200 škôl projekt „Digitálne učivo na dosah“.","article_id":"4","created":"25.2.2015","file":"http:\/\/edu.mkreo.sk\/img\/article\/app\/projekt-digitalne-ucivo-na-dosah-zvysi-kvalitu-vyucby-na-200-skolach-v-regionoch-slovenska-9.jpg"}]
       
    According to jsonlint.com validator it's valid JSON, on iOS JSON.parse hasn't any problem to parse it. On Android I have to use eval(), because of Android implementation of JSON methods(I read about it on Appcelerator's old Q&A, it's working normally). On Windows Phone, eval() cause application crash and JSON.parse throws common error ad can't parse it. If I set the first object of this json to variable as string, hyperlink is not escaped and it's parsed successfully(so for me is JSON.parse working partially) but if I read it from web via HTTPClient, it throws error. Thank you. P.S: question marks added to that JSON are added by text formatter in this JIRA, it's in Slovak language with diacritics
  4. Marian Kucharcik 2015-11-13

    Hi guys, I discovered, that at start of my JSON string, there is a blank space and this cause JSON.parse to throw error. After I removed that, everything works fine. Thank you

JSON Source