如何处理python中不规则的json文件,得到CSV中的序列化值?

2024-06-07 00:55:34 发布

您现在位置:Python中文网/ 问答频道 /正文

{\n      \"1 & 1 Internet\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 55,\n        \"abc\": \"low\"\n      },\n      \"1 website hosting\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 0,\n        \"abc\": \"poor\"\n      },\n      \"10000ft\": {\n        \"category\": \"Collaboration\",\n        \"xyz\": 48,\n        \"abc\": \"poor\"\n      },\n      \"1010data\": {\n        \"category\": \"Big Data\",\n        \"xyz\": 56,\n        \"abc\": \"low\"\n      },\n      \"101domains\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 0,\n        \"abc\": \"poor\"\n      },\n      \"111WebHost.com\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 6,\n        \"abc\": \"poor\"\n      },\n      \"11Giraffes\": {\n        \"category\": \"Web Design\",\n        \"xyz\": 0,\n        \"abc\": \"poor\"\n      },\n      \"123 FlashChat\": {\n        \"category\": \"Collaboration\",\n        \"xyz\": 64,\n        \"abc\": \"medium\"\n      },\n      \"123-Hosts\": {\n        \"category\": \"Web Design & Infrastructure\",\n        \"xyz\": 0,\n        \"abc\": \"poor\"\n      },\n      \"123-reg\": {\n        \"category\": \"Web Design & Infrastructure\",\n        \"xyz\": 52,\n        \"abc\": \"low\"\n      },\n      \"123ContactForm\": {\n        \"category\": \"Survey Solutions\",\n        \"xyz\": 43,\n        \"abc\": \"poor\"\n      },\n      \"123LandLord\": {\n        \"category\": \"Asset Management\",\n        \"xyz\": 18,\n        \"abc\": \"poor\"\n      },\n      \"123connect\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 8,\n        \"abc\": \"poor\"\n      },\n      \"15Five\": {\n        \"category\": \"Telecom\",\n        \"xyz\": 49,\n        \"abc\": \"poor\"\n      },\n      \"15MinuteServers\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 13,\n        \"abc\": \"poor\"\n      },\n      \"1ShoppingCart\": {\n        \"category\": \"Software Development\",\n        \"xyz\": 27,\n        \"abc\": \"poor\"\n      },\n      \"1Web Hosting\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 3,\n        \"abc\": \"poor\"\n      },\n      \"1st Domains\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 19,\n        \"abc\": \"poor\"\n      },\n      \"1st Easy\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 51,\n        \"abc\": \"low\"\n      },\n      \"1st4webshops\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 12,\n        \"abc\": \"poor\"\n      },\n      \"1stDNS Limited\": {\n        \"category\": \"Infrastructure\",\n        \"xyz\": 0,\n        \"abc\": \"poor\"\n      },\n      \"1time\": {\n        \"category\": \"Expense Management\",\n        \"xyz\": 12,\n        \"abc\": \"poor\"\n      },\n      \"2001 Web\": {\n        \"category\": \"Web Design & Infrastructure\",\n        \"xyz\": 24,\n        \"abc\": \"poor\"\n      },\n      \"23Video\": {\n        \"category\": \"Content Management\",\n        \"xyz\": 31,\n        \"abc\": \"poor\"\n      },\n      \"24 Seven Office\": {\n        \"category\": \"Enterprise Resource Planning\",\n        \"xyz\": 14,\n        \"abc\": \"poor\"\n      }

输出:

1&1互联网,基础设施,55,低

基础设施差,0托管,1

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。在

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。在

以上提到的文件等等


Tags: web基础设施websitemanagementinternetinfrastructurelowdesign
1条回答
网友
1楼 · 发布于 2024-06-07 00:55:34
Python 2.7.8 (default, Oct 20 2014, 15:05:19) 
>>> data = """{\n      \"1 & 1 Internet\": {
...              \n        \"category\": \"Infrastructure\",
...              \n        \"xyz\": 55,
...              \n        \"ABC\": \"low\"
...              \n      },
...   \n      \"1 website hosting\": {
...              \n        \"category\": \"Infrastructure\",
...              \n        \"xyz\": 0,
...              \n        \"ABC\": \"poor\"
...              \n      },
...   \n      \"10000ft\": {
...              \n        \"category\": \"Collaboration\",
...              \n        \"xyz\": 48,
...              \n        \"ABC\": \"poor\"\n
... }"""
>>> import json
>>> json.loads(data)
...
ValueError: Expecting object: line 30 column 1 (char 489)

缺少右大括号:

^{pr2}$

相关问题 更多 >