Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4345322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:01:15+00:00 2026-05-21T12:01:15+00:00

I just wanted some input about my use of JSON. <?php header(‘Content-Type: text/plain’); //results

  • 0

I just wanted some input about my use of JSON.

<?php
header('Content-Type: text/plain');

//results
$results = array();
for($i=0;$i<20;$i++)
{
    $result = array();
    $result['name'] = 'Test Season '.ceil(($i+1)/13).' Episode '.(($i%13)+1);
    //$result['torrent'] = 'https://www.example.com/?id='.$i.'&key='.uniqid();
    $result['torrents'] = array();
        $c = mt_rand(1,4);
        for($j=0;$j<$c;$j++)
        {
            $torrent = array();
            $torrent['url'] = 'https://www.example.com/?id='.uniqid().'&key='.md5(uniqid());
            $torrent['codec'] = $j%2 == 0 ? 'xvid' : 'h264';
            $torrent['resolution'] = '720p';
            $result['torrents'][] = $torrent;
        }
    $results[] = $result; //push
}
echo json_encode($results);
?>

This is just some test code, not an actual implementation. Am I using JSON correctly and too the fullest? Or is some better method of doing this?

I have legal torrents that I’d like to do some JSON with.
Torrents are grouped by name which contain multiple torrents (actual links to data). And other information such as codec etc.

This is my first time actually outputting JSON, would XML be better?

Are there any guides on this topic (hopefully not entire books)?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:01:15+00:00Added an answer on May 21, 2026 at 12:01 pm

    What you doing is right. I like to use the StdClass to make objects rather than key value arrays, just cause it looks sexier! E.g.

    $torrent = new StdClass();
    $torrent->url = 'https://www.example.com/?id='.uniqid().'&key='.md5(uniqid());
    $torrent->codec = $j%2 == 0 ? 'xvid' : 'h264';
    $torrent->resolution = '720p';
    $result['torrents'][] = $torrent;
    

    As you say you don’t need to read a whole book on the matter, I would have a look here http://php.net/manual/en/book.json.php to get to grips with the basics of JSON.

    In terms of JSON vs XML, I find it far easier to represent data as JSON as it is easier to fetch the specific data you want much in the same way you can access the info in a stdClass object.

    [EDIT]
    And as Stefan Gehrig says make sure you define your content type as “application/json”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wanted some input on a project that I'm working on. Basically, I'm
Shell scripting newbie here. Just wanted some input on my shell script. I basically
I'm trying to understand a shell/bash script and just wanted input on the use
Just wanted some quick help I'm 90% sure i need to use the (this)
I just wanted some opinions from people that have run Selenium ( http://selenium.openqa.org )
I just wanted to do some tutorials in WPF but I find that the
I'm building a game server in Python and I just wanted to get some
I just wrote some code, looked it over, and wanted to cry. Lines that
I just wanted to discuss a topic which I am thinking about. I work
So I'm basically just trying to take in some file input, and then take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.