S
S
Sergey Andrianov2016-12-21 03:42:19
JavaScript
Sergey Andrianov, 2016-12-21 03:42:19

Parse JSON array?

$.ajax({
        url: "assets/ajax.php",
        dataType: "json",
        success: function(data){
            console.log(data);
        }
    });

I get this answer.
({"cnt_pay_s":"1 523","cnt_pay_z":"22 924","cnt_pay_a":"29 587","cnt_z":"227 450","cnt_s":"7 456","sum_z":"2 544 060 000","sum_s":"1 723 330 000"})

On data[0] displays a bracket "("

Tell me how to sort it out?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stalker_RED, 2016-12-21
@Batiss

You can trim the brackets, like this: data.slice(1, -1), for example .
But it is better, if possible, to correct the server part, the one that adds these extra brackets.

A
Alexander, 2016-12-21
@SmoKE_xD

tyk and json parse where?)

Y
YemSalat, 2016-12-21
@YemSalat

First you need to cut out the parentheses, and then `JSON.parse`

S
Sergey Andrianov, 2016-12-21
@Batiss

success: function(data){
            data = JSON.parse(data);
            console.log(data);
        }

leads to error
Uncaught SyntaxError: Unexpected token ( in JSON at position 0

I
Ivan, 2016-12-21
@LiguidCool

jQuery.getJSON()
You have one fig JQ connected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question