D
D
dimakruglyak2016-03-16 21:07:11
JavaScript
dimakruglyak, 2016-03-16 21:07:11

How to work with json on js?

<?php $file = file_get_contents("http://site.com/my.json");
$json = json_decode($file); ?>

<?php if ($json->vars->var1->active== 1) { ?>
  <div>text1</div>
<?} ?>

<?php if ($json->vars->var1->active== 0) { ?>
  <div>text2</div>
<?} ?>

How to do it in js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Stolyarov, 2016-03-16
@Ni55aN

var file = response; // полученный ответ сервера

var json = JSON.parse(file);

if(json.vars.var1.active == 1)
 //..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question