|
可以看到,它实际上什么也没有做。在这里隐式调用的 JSONObject 的 toString() 方法做了所有工作。请注意,application/x-json 内容类型还有一点不确定 —— 在编写这篇文章的时候,关于 JSON 应当属于什么 MIME 类型还没有定论。但是,目前 application/x-json 是合理的选择。清单 10 显示了这个 servlet 代码的示例响应。
清单 10. Customer bean 的 JSON 表示
[php]
{
"orders": [
{
"items": [
{
"price": "$49.99",
"description": "512 Megabyte Type 1 CompactFlash card.
Manufactured by Oolong Industries",
"name": "Oolong 512MB CF Card",
"id": "i-55768"
},
{
"price": "$299.99",
"description": "7.2 Megapixel digital camera featuring six
shooting modes and 3x optical zoom. Silver.",
"name": "Fujak Superpix72 Camera",
"id": "i-74491"
}
],
"date": "08-26-2005",
"cost": "$349.98",
"id": "o-11123"
}
],
"realname": "James Hyrax",
"username": "jimmy66"
}
........
[/php] |
|