json A 1
ada 2 file
1. index.html
2. articles.json
check this out :
1. ======== index.html ====== start
<html>
<head>
<title>json reading</title></head>
<body>
<script src="jquery-2.1.4.min.js"></script>
<script>
/*
$.getJSON('articles.json', function(data){
//console.log('it worked');
console.log(data);
});
*/
$.ajax({
url: 'articles.json',
dataType: 'json',
type: 'get',
cache: false,
success: function(data){
//console.log(data);
$(data.articles).each(function(index, value){
//console.log(value);
console.log(value.name);
});
}
});
</script>
</body>
</html>
1. ======== index.html ====== end
2. ======== 2. articles.json ====== start
{
"articles" : [
{
"id" : 1,
"name" : "Febrian"
},
{
"id" : 2,
"name" : "Rizkiono"
},
{
"id" : 3,
"name" : "FebrianRizkiono"
}
]
}
2. ======== 2. articles.json ====== end
========================================================================
JSON BBB 2
====== $output = json_encode($val); ======
=== print_r(json_decode($json)); ======
ada 3 file
1.json2.php
2.json 2-1.php
3.json 2-1.json
===== 1.json2.php=== start
<?php
$val = array(
"no"=>"1",
"nama"=>"febrian rizkiono",
"alamat"=>array(
"jalan"=>"soka 1 no 35",
"rt"=>"01",
"rw"=>"07"
),
"telp"=>"0987654321",
"universitas"=>array(
"nama"=>"gunadarma",
"alamat"=>"depok dan kelapa dua"
)
);
$output = json_encode($val);
echo $output;
?>
===== 1.json2.php=== end
====== 2.json 2-1.php ==== start
<?php
$json =
'
{
"no":"1",
"nama":"febrian rizkiono",
"alamat":{
"jalan":"soka 1 no 35",
"rt":"01",
"rw":"07"
},
"telp":"0987654321",
"universitas":{
"nama":"gunadarma",
"alamat":"depok dan kelapa dua"
}
}';
echo "<prev>";
print_r(json_decode($json));
echo "</prev>";
?>
====== 2.json 2-1.php ==== end
====== 3.json 2-1.json ===== start
<?php
$json =
'
{
"no":"1",
"nama":"febrian rizkiono",
"alamat":{"jalan":"soka 1 no 35","rt":"01","rw":"07"},"telp":"0987654321","universitas":{"nama":"gunadarma","alamat":"depok dan kelapa dua"}}
';
echo "<prev>";
print_r($json);
echo "</prev>";
?>
====== 3.json 2-1.json ===== end
ada 2 file
1. index.html
2. articles.json
check this out :
1. ======== index.html ====== start
<html>
<head>
<title>json reading</title></head>
<body>
<script src="jquery-2.1.4.min.js"></script>
<script>
/*
$.getJSON('articles.json', function(data){
//console.log('it worked');
console.log(data);
});
*/
$.ajax({
url: 'articles.json',
dataType: 'json',
type: 'get',
cache: false,
success: function(data){
//console.log(data);
$(data.articles).each(function(index, value){
//console.log(value);
console.log(value.name);
});
}
});
</script>
</body>
</html>
1. ======== index.html ====== end
2. ======== 2. articles.json ====== start
{
"articles" : [
{
"id" : 1,
"name" : "Febrian"
},
{
"id" : 2,
"name" : "Rizkiono"
},
{
"id" : 3,
"name" : "FebrianRizkiono"
}
]
}
2. ======== 2. articles.json ====== end
========================================================================
JSON BBB 2
====== $output = json_encode($val); ======
=== print_r(json_decode($json)); ======
ada 3 file
1.json2.php
2.json 2-1.php
3.json 2-1.json
===== 1.json2.php=== start
<?php
$val = array(
"no"=>"1",
"nama"=>"febrian rizkiono",
"alamat"=>array(
"jalan"=>"soka 1 no 35",
"rt"=>"01",
"rw"=>"07"
),
"telp"=>"0987654321",
"universitas"=>array(
"nama"=>"gunadarma",
"alamat"=>"depok dan kelapa dua"
)
);
$output = json_encode($val);
echo $output;
?>
===== 1.json2.php=== end
====== 2.json 2-1.php ==== start
<?php
$json =
'
{
"no":"1",
"nama":"febrian rizkiono",
"alamat":{
"jalan":"soka 1 no 35",
"rt":"01",
"rw":"07"
},
"telp":"0987654321",
"universitas":{
"nama":"gunadarma",
"alamat":"depok dan kelapa dua"
}
}';
echo "<prev>";
print_r(json_decode($json));
echo "</prev>";
?>
====== 2.json 2-1.php ==== end
====== 3.json 2-1.json ===== start
<?php
$json =
'
{
"no":"1",
"nama":"febrian rizkiono",
"alamat":{"jalan":"soka 1 no 35","rt":"01","rw":"07"},"telp":"0987654321","universitas":{"nama":"gunadarma","alamat":"depok dan kelapa dua"}}
';
echo "<prev>";
print_r($json);
echo "</prev>";
?>
====== 3.json 2-1.json ===== end
terima kasih, jsonnya manfaat yaa
BalasHapus