Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 692277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:03+00:00 2026-05-14T02:38:03+00:00

When i try to read a JSON string like below it goes to endless

  • 0

When i try to read a JSON string like below it goes to endless loop.

<script language="javascript">
           $(document).ready(function() {

               $("#Button1").click(function() {
                   var json = "[{'City':'Lucknow','ID':'1'},{'City':'Mumbai','ID':'2'}]";
                   $.each(json, function() {
                       alert(this['City']);
                  });


           });
    </script>

Not sure what i am doing wrong? Please helpme out!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:38:03+00:00Added an answer on May 14, 2026 at 2:38 am

    Use jQuery.parseJSON to parse the JSON string with jQuery:

    var json = "[{'City':'Lucknow','ID':'1'},{'City':'Mumbai','ID':'2'}]";
    $.each(jQuery.parseJSON(json), function() {
        alert(this['City']);
    });
    

    The advantage of jQuery.parseJSON is that it uses the native implementation JSON.parse of the browser if it supports it.


    Edit    The problem that this is not working is probably that JSON does only allow strings to be declared with double quotes. The corresponding excerpt from the JSON specification:

         string = quotation-mark *char quotation-mark
    
         char = unescaped /
                escape (
                    %x22 /          ; "    quotation mark  U+0022
                    %x5C /          ; \    reverse solidus U+005C
                    %x2F /          ; /    solidus         U+002F
                    %x62 /          ; b    backspace       U+0008
                    %x66 /          ; f    form feed       U+000C
                    %x6E /          ; n    line feed       U+000A
                    %x72 /          ; r    carriage return U+000D
                    %x74 /          ; t    tab             U+0009
                    %x75 4HEXDIG )  ; uXXXX                U+XXXX
    
         escape = %x5C              ; \
    
         quotation-mark = %x22      ; "
    
         unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
    

    So the following should work:

    var json = '[{"City":"Lucknow","ID":"1"},{"City":"Mumbai","ID":"2"}]';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ExtJs4 and I'm trying to extend the Ext.form.field.ComboBox like below: Ext.define('GenericCombo', {
hi everyone I try to read the information of this direction http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr SAXParserFactory factory=
Well I have a problem reading the JSON data in jQuery, which is outputted
I have HTTP Handler FaqsJson.ashx which is creating a JSON utilizing the StringBuilder. In
I'm having some problems with converting some JSON and I'm after some help. This
Possible Duplicate: Ruby/Ruby on Rails ampersand colon shortcut As a habit I try and
i have developed an application in which i fetch books using googleapibook search. I
Consider the following comma separated file. For simplicity let it contain one line: 'I
I've run into a very strange problem in Eclipse, and I'm not sure if
HI, I have a typical messages.properties file in my application. I'm trying to generate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.