1

json-serverJSONデータをREST APIとしてプッシュするために使用しています。

サーバーは次のような get 要求に対して (上記) を返します。

http://localhost:3000/items?itemid=534

戻る:

[
  {
    "itemid": 534,
    "type": "textcontent",
    "icon": "http://exampple.com/1png",
    "title": "John",
    "description": "Description",
    "url": "http://example.net/project/doSomething"
  }
]

返品はJSON array、致しませんJSON object

jsonオブジェクトを返すにはどうすればよいですか

データファイル: data.json

{
  "items": [
    {
      "itemid": 534,
    "type": "textcontent",
    "icon": "http://exampple.com/1png",
    "title": "John",
    "description": "Description",
    "url": "http://example.net/project/doSomething"
    },
    {
      "itemid": 234,
    "type": "textcontent",
    "icon": "http://exampple.com/2png",
    "title": "Smith",
    "description": "Description2",
    "url": "http://example.net/project/doSomething2"
    }
    ]
}
4

3 に答える 3

1

データを次のように変更した場合:

{
  "items": [
    {
      "id": 534,
      "type": "textcontent",
      "icon": "http://exampple.com/1png",
      "title": "John",
      "description": "Description",
      "url": "http://example.net/project/doSomething"
    },
    {
      "id": 234,
      "type": "textcontent",
      "icon": "http://exampple.com/2png",
      "title": "Smith",
      "description": "Description2",
      "url": "http://example.net/project/doSomething2"
    }
  ]
}

次に、次のような URL で個々のアイテムにアクセスできます: http://localhost:3000/items/534

于 2016-03-01T20:35:47.163 に答える