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

  • SEARCH
  • Home
  • 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 6768885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:07:39+00:00 2026-05-26T15:07:39+00:00

I’m trying to get Jquery to read a json file, But unfortunately I can

  • 0

I’m trying to get Jquery to read a json file,

But unfortunately I can not get it to work.

This is my json file. see: http://bitcoincharts.com/t/weighted_prices.json

{
    "USD": {"7d": "4.4549", "30d": "5.2016", "24h": "4.1373"}, 
    "GBP": {"7d": "2.9706", "30d": "3.2620", "24h": "2.5463"}, 
}

My jquery script looks like this

<script type="text/javascript">
 (document).ready(function(){
       $.getJSON('http://bitcoincharts.com/t/weighted_prices.json',function(data){
               $("#results").html(data[0].30d);
       });
});
</script>

I try to grab USD>30d>5.2016

  • 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-26T15:07:39+00:00Added an answer on May 26, 2026 at 3:07 pm

    To get USD -> 30d (= 5.2016) you need to do this:

    data["USD"]["30d"]
    

    You can’t say data[0] because using a numeric index is (generally) only applicable to arrays and you don’t have an array. You have an object with two properties, “USD” and “GBP”, and each of those properties has an object with the properties “7D”, “30d”, “24h”.

    In more detail:

    JavaScript array literal declarations use square brackets that contain simply a list of elements, like this:

    var myArray = ["a","b","c"];
    

    But object literal declarations use curly brackets with key-value pairs like in the JSON you provided in your question, or here’s a simpler example:

    var myObject = { "key1" : "value1", "key2" : "value2", "key3" : "value3" };
    

    The “trick” is that once defined both arrays and objects are accessed with the square bracket notation, but arrays use numeric indexes and objects use string keys.

    You can also use dot notation like you were trying to do, but only on properties with a key name that meets the rules of valid JavaScript identifiers, i.e., not starting with a number, no spaces, not a reserved word, etc. These restrictions only apply to dot notation though, so if you use the square bracket notation you can have spaces, numbers, etc.

    It’s fine to nest arrays and objects, including mixing the two, but in your particular case you just had an object containing two other objects, no arrays.

    So data["USD"] will give you {"7d": "4.4549", "30d": "5.2016", "24h": "4.1373"}.

    data["GBP"] will give you {"7d": "2.9706", "30d": "3.2620", "24h": "2.5463"}.

    You narrow it down to the individual value you want with data["USD"]["30d"].

    EDIT: Your $.getJSON request isn’t going to work because of the Ajax same-origin policy, i.e., you are only allowed to make JSON requests to the same domain as the current page’s.

    You could try JSONP – which jQuery supports with practically no effort on your part: you just have to add ?callback=? to the end of the url – except that JSONP requires support on the server and it looks like the bitcoin people don’t support it.

    So the easiest way forward is to get the data in your server side code where the same-origin policy won’t get in your way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.