JSON-RSS

Aus Imperia Support Wiki

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
  • <guid> wird immer angenommen mit isPermalink="false"

Es gibt generelle Regeln zum Umformen von XML in JSON.

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));

?>