JSON

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    JSON

    Hi,

    I have a file that returns JSON data:

    <?php
    $q = strtolower($_GE T["q"]);
    if (!$q) return;
    $items = array(
    "Peter Pan"=>"peter@pa n.de",
    "Molly"=>"molly @yahoo.com",
    "Forneria Marconi"=>"live @japan.jp",
    "Master Sync"=>"205bw@s amsung.com",
    "Dr. Tech de Log"=>"g15@logi tech.com",
    "Don Corleone"=>"don @vegas.com",
    "Mc Chick"=>"info@d onalds.org",
    "Donnie Darko"=>"dd@tim eshift.info",
    "Quake The Net"=>"webmaste r@quakenet.org" ,
    "Dr. Write"=>"write@ writable.com"
    );

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

    I want to create a test file that returns the following JSON:
    [{"TagID":"017b2 53e-596b-4328-85f5-
    fd97a783759c"," Name":"Física", "FileTags":[],"ProfessorTags ":[]},
    {"TagID":"3fae2 160-55f6-4dd0-b856-
    fd27f5d307e2"," Name":"Matemáti ca","FileTags ":[],"ProfessorTags ":[]},
    {"TagID":"883b1 97e-0cb3-4528-8403-0877d742bf47"," Name":"Matemáti ca
    B","FileTags ":[],"ProfessorTags ":[]},{"TagID":"f18 3cb9d-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

  • Matija Papec

    #2
    Re: JSON

    shapper wrote:
    Hi,
    >
    I have a file that returns JSON data:
    >
    <cut>
    echo "[";
    foreach ($items as $key=>$value) {
    if (strpos(strtolo wer($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

    Comment

    Working...