JSON

This is a discussion on JSON within the PHP Language forums, part of the PHP Programming Forums category; Hi, I have a file that returns JSON data: <?php $q = strtolower($_GET["q"]); if (!$q) return; $...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-13-2008
shapper
 
Posts: n/a
Default JSON

Hi,

I have a file that returns JSON data:

<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Peter Pan"=>"peter@pan.de",
"Molly"=>"molly@yahoo.com",
"Forneria Marconi"=>"live@japan.jp",
"Master Sync"=>"205bw@samsung.com",
"Dr. Tech de Log"=>"g15@logitech.com",
"Don Corleone"=>"don@vegas.com",
"Mc Chick"=>"info@donalds.org",
"Donnie Darko"=>"dd@timeshift.info",
"Quake The Net"=>"webmaster@quakenet.org",
"Dr. Write"=>"write@writable.com"
);

echo "[";
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "{ name: \"$key\", to: \"$value\" }, ";
}
}
echo "]";

I want to create a test file that returns the following JSON:
[{"TagID":"017b253e-596b-4328-85f5-
fd97a783759c","Name":"Física","FileTags":[],"ProfessorTags":[]},
{"TagID":"3fae2160-55f6-4dd0-b856-
fd27f5d307e2","Name":"Matemática","FileTags":[],"ProfessorTags":[]},
{"TagID":"883b197e-0cb3-4528-8403-0877d742bf47","Name":"Matemática
B","FileTags":[],"ProfessorTags":[]},{"TagID":"f183cb9d-9d92-4c61-b03a-
e51cc1205b2b","Name":"Português","FileTags":[],"ProfessorTags":[]}]

I am not familiar with PHP and I need to create this to test
something.

Thanks,
Miguel

Reply With Quote
  #2 (permalink)  
Old 07-14-2008
Matija Papec
 
Posts: n/a
Default Re: JSON

shapper wrote:
> Hi,
>
> I have a file that returns JSON data:
>

<cut>
> echo "[";
> foreach ($items as $key=>$value) {
> if (strpos(strtolower($key), $q) !== false) {
> echo "{ name: \"$key\", to: \"$value\" }, ";
> }
> }
> echo "]";
>
> I want to create a test file that returns the following JSON:



Look for json_encode and json_decode functions
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:30 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0