JSON-RSS: Unterschied zwischen den Versionen

Aus Imperia Support Wiki
(Implemenation: JSON-RSS)
Zeile 4: Zeile 4:
  
 
Datei-Endung: <code>.jrss</code>
 
Datei-Endung: <code>.jrss</code>
 +
 
MIME-Type: <code>application/rss+json</code>
 
MIME-Type: <code>application/rss+json</code>
  

Version vom 4. August 2011, 13:16 Uhr

Idee: Ein Nachrichtenaustauschformat analog zu RSS, aber leichtgewichtiger zu parsen.

Implemenation: JSON-RSS

Datei-Endung: .jrss

MIME-Type: application/rss+json

Codebeispiel:

{
    "version":"2.0",
    "channel":
    {
        "title":"TITLE",
        "link":"http:\/\/example.com\/",
        "description":"A test",
        "lastBuildDate":"Mon, 04 Aug 2011 16:50:00 +0000",
        "pubDate":"Mon, 04 Aug 2011 16:45:00 +0000",
        "items":
        [
            {
                "guid":"1",
                "title":"Example entry",
                "link":"http:\/\/example.com\/test",
                "description":"This test<br />contains HTML.",
                "pubDate":"Mon, 04 Aug 2011 16:45:00 +0000",
                "enclosure":
                {
                    "url":"http:\/\/example.com\/file.mp3",
                    "length":"123456789",
                    "type":"audio\/mpeg"
                }
                "categories":
                [
                    "test"
                ]
            },
            {
                "guid":"2",
                "title":"Another example entry",
                "link":"This test does not contain HTML.",
                "description":"http:\/\/example.com\/another_test",
                "pubDate":"Mon, 04 Aug 2011 17:25:00 +0000"
            }
        ]
    }
}

Besonderheiten sind:

  • Die RSS-Versionsnummer wird eine eigenständige Eigenschaft
  • <item> wird zu einem Array names "items"
  • <category> wird zu einem Array names "categories"
  • <enclosure> wird zu einem Objekt
  • <guid> wird immer angenommen mit isPermalink="false"

Generierung per PHP z.B.

<?php

    $rss = (object)array(
        'version' => '2.0',
        'channel' => (object)array(
            'title' => 'TITLE',
            'link' => 'http://example.com/',
            'description' => 'A test',
            'lastBuildDate' => 'Mon, 04 Aug 2011 16:50:00 +0000',
            'pubDate' => 'Mon, 04 Aug 2011 16:45:00 +0000',
            'items' => array(
                (object)array(
                    'guid' => '1',
                    'title' => 'Example entry',
                    'link' => 'http://example.com/test',
                    'description' => 'This test<br />contains HTML.',
                    'pubDate' => 'Mon, 04 Aug 2011 16:45:00 +0000',
                    'enclosure' => (object)array(
                        'url'=>'http://example.com/file.mp3',
                        'length'=>'123456789',
                        'type'=>'audio/mpeg',
                    ),
                    'categories' => array('test'),
                ),
                (object)array(
                    'guid' => '2',
                    'title' => 'Another example entry',
                    'link' => 'This test does not contain HTML.',
                    'description' => 'http://example.com/another_test',
                    'pubDate' => 'Mon, 04 Aug 2011 17:25:00 +0000',
                ),
            ),
        ),
    );
    
    echo(json_encode($rss));

?>