O
O
OKNOZA2015-11-23 21:32:42
JavaScript
OKNOZA, 2015-11-23 21:32:42

How to pull c localstorage json using jquery and read?

How to read localstorage jsone key using jquery ?
There is a code:

function ref_cart() {
    var output = "";
    var allCnt = 0;

    $(".cart li").remove();
    for (var i = 0; i < localStorage.length; i++) {
      output += "<li>ID: "+localStorage.key(i)+" | Количество: "+localStorage.getItem(localStorage.key(i))+" <button data-pr='"+localStorage.key(i)+"' class='remove'> X </button></li>";
      allCnt = + parseInt(localStorage.getItem(localStorage.key(i))) + allCnt;
    }
    output += "<li>Общий метраж: " + allCnt + " метров</li>";
    
    $(".cart").append(output);
  }

The output is like this from localstorage
ID: pr1 | Quantity: {"name":"coarse calico";"coutTX":600; "priceTX": 0.3}

Help read Coarse calico - 600 - 0.3
Otherwise, it outputs a Json string, but is not strong in JS.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-11-23
@Stalker_RED

https://developer.mozilla.org/en/docs/Web/JavaScript...

A
Alexander Taratin, 2015-11-23
@Taraflex

https://api.jquery.com/jquery.parsejson/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question