无法在熊猫中读取JSON

时间:2017-06-07 18:56:03

标签: json pandas

我有一个嵌套的JSON。我想让它在熊猫中阅读以便探索它,但我得到了错误。何时使用read_json方法,我得到:“尾随数据”。它是有效的JSON。如何在pd中阅读? (尝试不同,但没有奏效)。它看起来像这样:

{
"contributors": null,
"coordinates": null,
"created_at": "Fri May 26 08:54:00 +0000 2017",
"entities": {
    "hashtags": [],
    "media": [
        {
            "display_url": "pic.twitter.com/Pm28ORTePl",
            "expanded_url": "",
            "id": 868027417121751040,
            "id_str": "868027417121751040",
            "indices": [
                94,
                117
            ],
            "media_url": "",
            "sizes": {
                "large": {
                    "h": 404,
                    "resize": "fit",
                    "w": 773
                },
                "medium": {
                    "h": 404,
                    "resize": "fit",
                    "w": 773
                },
                "small": {
                    "h": 355,
                    "resize": "fit",
                    "w": 680
                },
                "thumb": {
                    "h": 150,
                    "resize": "crop",
                    "w": 150
                }
            },
            "type": "photo",
            "url": ""
        }
    ],
    "symbols": [],
    "urls": [
        {
            "display_url": "",
            "expanded_url": "",
            "indices": [
                70,
                93
            ],
            "url": ""
        }
    ],
    "user_mentions": []
},
"extended_entities": {
    "media": [
        {
            "display_url": "pic.twitter.com/Pm28ORTePl",
            "expanded_url": "1",
            "id": 868027417121751040,
            "id_str": "868027417121751040",
            "indices": [
                94,
                117
            ],
            "media_url": "",
            "media_url_https": "",
            "sizes": {
                "large": {
                    "h": 404,
                    "resize": "fit",
                    "w": 773
                },
                "medium": {
                    "h": 404,
                    "resize": "fit",
                    "w": 773
                },
                "small": {
                    "h": 355,
                    "resize": "fit",
                    "w": 680
                },
                "thumb": {
                    "h": 150,
                    "resize": "crop",
                    "w": 150
                }
            },
            "type": "photo",
            "url": ""
        }
    ]
},
"favorite_count": 1,
"favorited": false,
"geo": null,
"id": 868027425757724672,
"id_str": "868027425757724672",
"in_reply_to_screen_name": null,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"is_quote_status": false,
"lang": "ru",
"place": null,
"possibly_sensitive": false,
"retweet_count": 0,
"retweeted": false,
"source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
"text": "\u041f\u0440\u043e\u043f\u0430\u0432\u0448\u0430\u044f \u0432 \u041a\u043e\u043a\u0448\u0435\u0442\u0430\u0443 \u0448\u043a\u043e\u043b\u044c\u043d\u0438\u0446\u0430 \u0436\u0438\u043b\u0430 \u0432 \u0437\u0430\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u043c \u0434\u043e\u043c\u0435 \u0438 \u0431\u0440\u043e\u0434\u044f\u0436\u043d\u0438\u0447\u0430\u043b\u0430\n",
"truncated": false,
"user": {
    "contributors_enabled": false,
    "created_at": "Wed May 18 11:59:50 +0000 2011",
    "default_profile": true,
    "default_profile_image": false,
    "description": "\u041a\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043d\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043f\u043e\u0440\u0442\u0430\u043b",
    "entities": {
        "description": {
            "urls": []
        },
        "url": {
            "urls": [
                {
                    "display_url": "",
                    "expanded_url": "",
                    "indices": [
                        0,
                        22
                    ],
                    "url": ""
                }
            ]
        }
    },
    "favourites_count": 87,
    "follow_request_sent": false,
    "followers_count": 17989,
    "following": true,
    "friends_count": 98,
    "geo_enabled": true,
    "has_extended_profile": false,
    "id": 300811189,
    "id_str": "300811189",
    "is_translation_enabled": false,
    "is_translator": false,
    "lang": "ru",
    "listed_count": 86,
    "location": "\u0410\u043b\u043c\u0430\u0442\u044b",
    "name": "",
    "notifications": false,
    "profile_background_color": "C0DEED",
    "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_tile": false,
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/300811189/1489117916",
    "profile_image_url": "http://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
    "profile_link_color": "1DA1F2",
    "profile_sidebar_border_color": "C0DEED",
    "profile_sidebar_fill_color": "DDEEF6",
    "profile_text_color": "333333",
    "profile_use_background_image": true,
    "protected": false,
    "screen_name": "",
    "statuses_count": 53011,
    "time_zone": "Quito",
    "translator_type": "none",
    "url": "",
    "utc_offset": -18000,
    "verified": false
}

}

1 个答案:

答案 0 :(得分:0)

很抱歉,但是你的JSON实际上是无效的,尽管你说的是。

这一行: UPDATE Record SET Status = 1 WHERE Status = 0 AND EntityID = @EntityID INSERT INTO Record(EntityID, Value, Status) VALUES(@EntityID, 100, 0) DECLARE @RecordID INT = @@IDENTITY UPDATE Entity SET CurrentRecordID = RecordID WHERE ID = @EntityID

应该是: "media_url": "": "",

此时,当我添加了代码块之外的最后一个"media_url": "",时,验证为正确形成的JSON。