2

I created a fiddle here.

How to calculate the currencies values by reading data from the localStorage? can anyone tel me steps to achieve this target?

i have jason data obtained by calling remote websites as below

{
    "list": {
        "meta": {
            "type": "resource-list",
            "start": 0,
            "count": 168
        },
        "resources": [{
                "resource": {
                    "classname": "Quote",
                    "fields": {
                        "name": "USD/KRW",
                        "price": "1062.280029",
                        "symbol": "KRW=X",
                        "ts": "1396294510",
                        "type": "currency",
                        "utctime": "2014-03-31T19:35:10+0000",
                        "volume": "0"
                    }
                }
            }, {
                "resource": {
                    "classname": "Quote",
                    "fields": {
                        "name": "SILVER 1 OZ 999 NY",
                        "price": "0.050674",
                        "symbol": "XAG=X",
                        "ts": "1396287757",
                        "type": "currency",
                        "utctime": "2014-03-31T17:42:37+0000",
                        "volume": "217"
                    }
                }
            }


        ]
    }
}

i am actually learning how to use javascript by dealing with localstorages. I am a serverside programmer, this is my 3rd day of javascript programming. Hope someone can help me here

4
  • use this function JSON.parse. to get data back in JSON form otherwise its just string in json form Commented Apr 1, 2014 at 16:32
  • @BluAngel could not understand what you mean, can you update my fiddle! Commented Apr 1, 2014 at 16:36
  • Currently in your example you store all json data in localStorge that you got from server. Now you just want to get data back from there(localStorage)? Commented Apr 1, 2014 at 16:40
  • posted answer if still any confusion than you can ask i will try to help Commented Apr 1, 2014 at 16:49

2 Answers 2

5

JSON.stringify is a serialization function. The unserialize function is called JSON.parse.

Sign up to request clarification or add additional context in comments.

1 Comment

don't know what you are telling me to do? Can you please tell me in detail
1

In your code localStorage.setItem('all_currencies',JSON.stringify(d)); this line converts your JSON Object to String so it can store in localStorage Now for get data back from there you have to write

var jsonStringFromLS = localStorage.getItem('all_currencies');

Now in jsonStringFromLS you have all data in string form to convert into Object pass this value into following function

console.log(JSON.parse(jsonStringFromLS));

from above line you get your data back in JSON object form so you can now process this object.

Demo

3 Comments

oh! now i understood what you said. But again how to convert currencies as shown in fiddle jsfiddle.net/AZnQp/9 ?
Now you can process your json object using some like for loop or for(key in data) loop (foreach)
also check this it will increase your understanding mkyong.com/javascript/how-to-access-json-object-in-javascript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.