json feed作为SSIS中的数据源 [英] json feed as a datasource in SSIS

查看:108
本文介绍了json feed作为SSIS中的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从openweathermap.org api反序列化json提要.经过大量尝试,使用脚本转换任务,我得到的只是错误甚至 不同的.基于由JSON2cscharp生成的以下类,我应该如何为每个语句编写代码(因为Weather和Main类是RootObject类的一部分)?我什至可以从api而不是JSON获取XML数据.实施该方法会更容易吗 XML处理?我不是要答案,只是要开始.

I am trying to de-serialize a json feed from openweathermap.org api. After a lot of tries all, using script transformation task, all I get are errors and even different ones. Based on the below classes, generated by JSON2cscharp, how I should write the for each statements (as class Weather and Main are part of class RootObject)? I can get even XML data from api, instead of JSON. Would it be easier to implement the process on XML? I am not asking for the answer, just a push to start.

JSON

{
    "coord":
        { "lon": -122.08, "lat": 37.39 },
    "weather": [{ "id": 741, "main": "Fog", "description": "fog", "icon": "50n" }],
    "base": "stations", "main":
        { "temp": 286.14, "pressure": 1022, "humidity": 82, "temp_min": 285.15, "temp_max": 287.15 },
    "visibility": 16093, "wind": { "speed": 1.11, "deg": 13.5055 },
    "clouds": { "all": 1 },
    "dt": 1479110160, "sys":
        { "type": 1, "id": 397, "message": 0.1452, "country": "US", "sunrise": 1479134859, "sunset": 1479171466 },
    "id": 5375480, "name": "Mountain View", "cod": 200
}

public class Coord
{
    public double lon { get; set; }
    public double lat { get; set; }
}

public class Weather
{
    public int id { get; set; }
    public string main { get; set; }
    public string description { get; set; }
    public string icon { get; set; }
}

public class Main
{
    public double temp { get; set; }
    public int pressure { get; set; }
    public int humidity { get; set; }
    public double temp_min { get; set; }
    public double temp_max { get; set; }
}

public class Wind
{
    public double speed { get; set; }
    public double deg { get; set; }
}

public class Clouds
{
    public int all { get; set; }
}

public class Sys
{
    public int type { get; set; }
    public int id { get; set; }
    public double message { get; set; }
    public string country { get; set; }
    public int sunrise { get; set; }
    public int sunset { get; set; }
}

public class RootObject
{
    public Coord coord { get; set; }
    public List<Weather> weather { get; set; }
    public string @base { get; set; }
    public Main main { get; set; }
    public int visibility { get; set; }
    public Wind wind { get; set; }
    public Clouds clouds { get; set; }
    public int dt { get; set; }
    public Sys sys { get; set; }
    public int id { get; set; }
    public string name { get; set; }
    public int cod { get; set; }
}







推荐答案

Proffesore,

Hi Proffesore,

谢谢您在这里发布.

对于您的问题,请尝试以下操作.

For your question, please try the following.

这是代码.

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace json_file2
{
    class Program
    {
        static void Main(string[] args)
        {
            string JSON = @"{
            'coord': { 'lon': -122.08, 'lat': 37.39 },
            'weather': [{ 'id': 741, 'main': 'Fog', 'description': 'fog', 'icon': '50n' }],
            'base': 'stations', 
            'main': { 'temp': 286.14, 'pressure': 1022, 'humidity': 82, 'temp_min': 285.15, 'temp_max': 287.15 },
            'visibility': 16093, 
            'wind': { 'speed': 1.11, 'deg': 13.5055 },
            'clouds': { 'all': 1 },
            'dt': 1479110160, 
            'sys': { 'type': 1, 'id': 397, 'message': 0.1452, 'country': 'US', 'sunrise': 1479134859, 'sunset': 1479171466 },
            'id': 5375480, 
            'name': 'Mountain View', 
            'cod': 200}";
            RootObject obj = JsonConvert.DeserializeObject<RootObject>(JSON);
            foreach (var item in obj.weather)
            {
                Console.WriteLine("id:{0}, main:{1}, description:{2}, icon:{3}", item.id, item.main, item.description, item.icon);
            }
            Console.ReadKey();
        }       
    }
   
    public class Coord
    {
        public double lon { get; set; }
        public double lat { get; set; }
    }

    public class Weather
    {
        public int id { get; set; }
        public string main { get; set; }
        public string description { get; set; }
        public string icon { get; set; }
    }

    public class Main
    {
        public double temp { get; set; }
        public int pressure { get; set; }
        public int humidity { get; set; }
        public double temp_min { get; set; }
        public double temp_max { get; set; }
    }

    public class Wind
    {
        public double speed { get; set; }
        public double deg { get; set; }
    }

    public class Clouds
    {
        public int all { get; set; }
    }

    public class Sys
    {
        public int type { get; set; }
        public int id { get; set; }
        public double message { get; set; }
        public string country { get; set; }
        public int sunrise { get; set; }
        public int sunset { get; set; }
    }

    public class RootObject
    {
        public Coord coord { get; set; }
        public Weather[] weather { get; set; }
        public string @base { get; set; }
        public Main main { get; set; }
        public int visibility { get; set; }
        public Wind wind { get; set; }
        public Clouds clouds { get; set; }
        public int dt { get; set; }
        public Sys sys { get; set; }
        public int id { get; set; }
        public string name { get; set; }
        public int cod { get; set; }
    }
}

这是输出.


我希望这会对您有所帮助.

I hope this would be helpful to you.

如果还有其他问题,请随时与我们联系.

If you have something else, please feel free to contact us.

最好的问候,

温迪


这篇关于json feed作为SSIS中的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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