gpt4 book ai didi

javascript - 将 JSON 从 API 转换为事件流

转载 作者:搜寻专家 更新时间:2023-11-01 00:05:20 25 4
gpt4 key购买 nike

我正在做一个有趣的项目,其中一个要求是从我选择的 API 中获取 JSON 数据,并使用 angularjs 将其转换为事件流。

我用谷歌搜索并阅读了什么是事件流,我相信我对它有基本的了解。它本质上是使用关键字“actor”、“verb”、“object”和“target”将 Action 转换为特定的 JSON 格式。

当我查看示例时,我理解了为什么特定的 JSON 字符串被视为事件流。

例子:

  {
"published": "2011-02-10T15:04:55Z",
"actor": {
"url": "http://example.org/martin",
"objectType" : "person",
"id": "tag:example.org,2011:martin",
"image": {
"url": "http://example.org/martin/image",
"width": 250,
"height": 250
},
"displayName": "Martin Smith"
},
"verb": "post",
"object" : {
"url": "http://example.org/blog/2011/02/entry",
"id": "tag:example.org,2011:abc123/xyz"
},
"target" : {
"url": "http://example.org/blog/",
"objectType": "blog",
"id": "tag:example.org,2011:abc123",
"displayName": "Martin's Blog"
}

但我对如何将我的 JSON 数据转换为事件流感到困惑。

我的 JSON 没有“ Actor ”,也没有“动词”。如果有人可以解释或提供解决方案,我们将不胜感激。谢谢!

天气 API

{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 300,
"main": "Drizzle",
"description": "light intensity drizzle",
"icon": "09d"
}
],
"base": "stations",
"main": {
"temp": 280.32,
"pressure": 1012,
"humidity": 81,
"temp_min": 279.15,
"temp_max": 281.15
},
"visibility": 10000,
"wind": {
"speed": 4.1,
"deg": 80
},
"clouds": {
"all": 90
},
"dt": 1485789600,
"sys": {
"type": 1,
"id": 5091,
"message": 0.0103,
"country": "GB",
"sunrise": 1485762037,
"sunset": 1485794875
},
"id": 2643743,
"name": "London",
"cod": 200
}

最佳答案

ActivityStream 只是事件的规范。天气只是一个模型。模型可以是主体/参与者,也可以是参与者作用于的对象。在这种情况下,天气只能是一个对象。

处理天气的事件示例是:

Martin checks the weather for London at 3:04 PM UTC on February 10, 2015.

对应的事件JSON为:

{
"published": "2015-02-10T15:04:55Z",
"actor": {
"url": "http://example.org/martin",
"objectType" : "person",
"id": "tag:example.org,2011:martin",
"image": {
"url": "http://example.org/martin/image",
"width": 250,
"height": 250
},
"displayName": "Martin Smith"
},
"verb": "search",
"object" : {
"url": "http://api.openweathermap.org/data/2.5/weather?q=London",
"name": "London's weather",
"published": "2015-02-10T15:04:55Z"
}
}

请注意,这只是一个示例。您可能有不同的事件,具体取决于您希望如何使用天气数据。

关于javascript - 将 JSON 从 API 转换为事件流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44900776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com