将JSON从API转换为活动流 [英] Transforming JSON from API into an activity stream

查看:142
本文介绍了将JSON从API转换为活动流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个有趣的项目,其中一项要求是从我选择的API中获取JSON数据,然后使用angularjs将其转换为活动流.

I am doing a project for fun and one of the requirements is to the JSON data from an API of my choice and transform it into an activity stream using angularjs.

我已经在Google上搜索并阅读了活动流,我相信我对此有基本的了解.它实质上是使用关键字"actor","verb","object"和"target"将动作转换为特定的JSON格式.

I've googled and read what an activity stream is and I believe I have a basic understanding of it. It's essentially transforming an action into a specific JSON format using the keywords "actor", "verb", "object", and "target".

当我看示例时,我理解为什么将特定的JSON字符串视为活动流.

When I look at examples, I understand why that specific JSON string is considered an activity stream.

示例:

  {
"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数据转换为活动流感到困惑.

But I'm confused in terms of how to transform my JSON Data into an activity stream.

我的JSON没有演员",也没有动词".如果有人可以解释或提供解决方案,将不胜感激.谢谢!

My JSON doesn't have an "actor", nor does it have a "verb". If anyone can please explain or provide a solution that would be greatly appreciated. Thank you!

天气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
}

推荐答案

活动流的概念非常简单.这是一个很好的例子:温迪将伦敦添加到她的游览地点列表中"

The activity stream concept is pretty simple. Here's a good example: "Wendy adds London to her list Places to visit"

在这种情况下,演员是温迪",对象是伦敦",动词是加",而 target 是游览地点".

In this case the actor is "wendy", the object is "london" the verb is "add" and the target is "places to visit".

您可以使用此语法来支持不同的用例.我见过人们,它是活动流规范,涵盖从建筑物的利兹认证,错误报告到社交应用程序的所有内容.

You can use this syntax to support different use cases. I've seen people us it the activity stream spec for everything ranging from Leed certification of buildings, error reporting to social apps.

示例2:

应用程序Uber崩溃,错误代码为2,并已分配给约翰

Application Uber broke down with error code 2 and has been assigned to John

  • 演员:application:uber
  • 动词:休息
  • 对象:错误:2
  • 目标:用户:John

示例3:

RoadToVR发表了有关Echo Arena的文章

RoadToVR published an article about Echo Arena

  • 演员:RoadToVR
  • 动词:已发布
  • 对象:Article:123

高级字段

该规范还概述了"TO"字段.您可以使用TO字段来支持@提及,主题标签和通知.

The spec also outlines the TO field. You can use the TO field to support @mentions, hashtags and notifications.

版本2

还有一个新版本的活动流规范可用: https://www.w3.org/TR/activitystreams-core/ 到目前为止,我还没有任何证据表明应用程序采用了这一新规范.

There is also a new version of the activity stream spec available: https://www.w3.org/TR/activitystreams-core/ So far I don't see any evidence of applications adopting this new spec.

活动流教程

如果您要构建Twitter样式供稿,则本教程是一个不错的起点: https://getstream.io/get_started/

This tutorial is a nice starting point if you want to build a Twitter style feed: https://getstream.io/get_started/

这篇关于将JSON从API转换为活动流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆