×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    WRT cannot parse JSON string.

    Hi.

    I am developing a new application that accepts JSON string from the server using Twisted framework. I am using Eclipse as IDE with Aptana and WRT plugin.

    When I'm testing the application using the emulator and Firefox, the app can parse the JSON perfectly. But when I try it on the device, specifically N78 and N96, the JSON parser returns a SyntaxError on JSON.parse. I have already used json2.js, json.js, json_parse.js and their previous versions to no avail.

    Note that when I ran this code using Opera Widget, it is working perfectly just like the emulator. My guess is that there is some conflict between Twisted, WRT, and the browser.

    This is where the error occurs on javascript:
    Code:
    var respObj = JSON.parse(xmlhttp.responseText);
    The following code is how python serializes a JSON object to a JSON formatted string:
    Code:
    self.request.write(simplejson.dumps(self.reply))
    self.request.finish()
    Here is a sample JSON I'm passing to WRT from Twisted:
    *actual JSON format sent to WRT:
    Code:
    {"Login-Response": {"SessionID": "8q7l8auzi0", "Contacts": {"All Contacts": {"wv:hello.world@gmail.com": {"OnlineStatus": "F"}}, "NEW LIST": {"wv:hello@gmail.com": {}}, "My Friends": {}}}}
    *the following has been indented by 5 spaces for readability
    Code:
     {
          "Login-Response": {
               "SessionID": "8q7l8auzi0", 
               "Contacts": {
                    "All Contacts": {
                         "wv:hello.world@gmail.com": {
                              "OnlineStatus": "F"
                         }
                    }, 
                    "NEW LIST": {
                         "wv:hello@gmail.com": {}
                    }, 
                    "My Friends": {}
               }
          }
     }
    Is there anything I am doing wrong? If you need more info, I'll gladly provide it.

    Thanks,
    Aceley
    Last edited by ace.david; 2009-12-10 at 15:23.

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: WRT cannot parse JSON string.

    Hello,

    I just ran some tests with the JSON data you provided and json2.js. For some reason it fails with N96 as you said, but works with N97 (Browser 7.1). Have to investigate more, but I would say this is some issue with OSS browser 3.2 which is used in N96.

    Br,
    Ilkka - FN

  3. #3
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Akron Ohio USA
    Posts
    229

    Re: WRT cannot parse JSON string.

    is there a way you can test the object names with underscore instead of the space? so instead of

    "All Contacts"

    You would have

    "All_Contacts"

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    Re: WRT cannot parse JSON string.

    hi,

    @isalento - thank you very much for that information. I'll try using the Nokia N97 and see if it works. It is very much possible that this is a browser issue since JSON.parse() works perfectly on Opera Widget installed on Nokia N96.

    @hp3 - thanks. I'll try your suggestion since I've ran out of options right now.

    I'll post the results as soon as I have them.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    Re: WRT cannot parse JSON string.

    I tried using Nokia N97 and it works. So this is an issue on some s60 devices.I also tried removing the whitespaces but it did not work. Maybe someone from Nokia could help us for possible work around on this issue.

    Br,
    Aceley

  6. #6
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: WRT cannot parse JSON string.

    Ok it seems that json2.js fails when in the first phase of parsing - replacing unicode characters with escape sequences.

    cx.test(text) will return true on N96 and after that it will try to replace all of the characters with escaped ones. So most likely this is a bug in the regular expression handling. It seems to work if you just comment unicode replacing part out, but I don't know if it has any side effects.

    -Ilkka

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    Re: WRT cannot parse JSON string.

    Quote Originally Posted by isalento View Post
    Ok it seems that json2.js fails when in the first phase of parsing - replacing unicode characters with escape sequences.

    cx.test(text) will return true on N96 and after that it will try to replace all of the characters with escaped ones. So most likely this is a bug in the regular expression handling. It seems to work if you just comment unicode replacing part out, but I don't know if it has any side effects.

    -Ilkka
    Thanks Ilkka. That seems to be a very plausible work around. Though just like what you said, parsing JSON may become very unstable/unpredictable with these devices.

  8. #8
    Registered User
    Join Date
    Mar 2007
    Location
    Warsaw
    Posts
    5

    Re: WRT cannot parse JSON string.

    Anyone can confirm is still issue is stil valid? I have just started developing one widget and I would like to avoid JSON parsing problems.
    http://bluszcz.net
    http://glam.pl - secondhand clothes

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Re: WRT cannot parse JSON string.

    The problem still remains. All other browsers work fine while testing (mobile browsers & desktop browsers & even the S40 Web proxy runs the script well), but WRT throws a parsererror. Seems parsing JSON string is a big problem on S60 devices.

  10. #10
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: WRT cannot parse JSON string.

    Quote Originally Posted by barbietunnie View Post
    The problem still remains. All other browsers work fine while testing (mobile browsers & desktop browsers & even the S40 Web proxy runs the script well), but WRT throws a parsererror. Seems parsing JSON string is a big problem on S60 devices.
    Hi and welcome to forum!
    On what device are you seeing this issue? Original issue was reported against OSS Browser 3.2 on N96, but worked already back then in N97 having browser 7.1.
    At the moment newest browser is 8.2 in Belle FP1.

    Br,
    Ilkka

Similar Threads

  1. Parse xml String
    By devdattac in forum Symbian
    Replies: 5
    Last Post: 2009-07-08, 11:48
  2. how to parse xml format string using cparse
    By nokia_lin in forum Symbian
    Replies: 8
    Last Post: 2009-07-08, 08:14
  3. C++ 學習程序2
    By hanwen813 in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 32
    Last Post: 2009-04-02, 09:10
  4. What is WRT 1.0, 1.1, 1.2 versions?
    By naroori in forum Symbian
    Replies: 2
    Last Post: 2008-12-24, 20:07
  5. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×