Loading ...
Sorry, an error occurred while loading the content.

Re: [json] Json - Is the best choice for my requirement

Expand Messages
  • Philip Tellis
    ... As far as javascript is concerned, JSON is as good as a regular object, so your data would be something like this: var data = [ { country : USA ,
    Message 1 of 2 , Jul 30, 2008
    View Source
    • 0 Attachment
      2008/7/30 sprakash_it <prakash123@...>:
      > Have a list of 500 country data
      >
      > COUNTRY
      > COUNTRY CODE
      > COUNTRY TAX CODE
      > COUNTRY TAX YEAR
      >
      > The user selects a country from an online form, and the corresponding
      > JS variables get populated, with the country related fields.
      >
      > Will JSON solve this purpose. What are CONS?

      As far as javascript is concerned, JSON is as good as a regular
      object, so your data would be something like this:

      var data = [
      { "country": "USA", "country_code": "US", "country_tax_code": 123,
      "country_tax_year": "01-12"},
      { "country": "India", "country_code": "IN", "country_tax_code":
      234, "country_tax_year": "04-03"},
      ...
      ];

      so when the user selects something from the form, you iterate through
      the list, and get the corresponding object out (assume the selected
      country is stored in the variable ccode):

      var info=null;
      for(var i=0; i<data.length; i++)
      {
      if(data[i]["country_code"] == ccode)
      {
      info = data[i];
      break;
      }
      }

      or maybe something like this:

      var data = {
      "US": { "country": "USA", "country_code": "US", "country_tax_code":
      123, "country_tax_year": "01-12"},
      "IN": { "country": "India", "country_code": "IN",
      "country_tax_code": 234, "country_tax_year": "04-03"},
      ...
      };

      so when the user selects a country from the list, you can just do this:

      var info = data[ccode];

      Then you can access any of your information like this:

      var tax_code = info["country_tax_code"];


      Hope this helps.

      Philip
    Your message has been successfully submitted and would be delivered to recipients shortly.