用 SuperObject 解析淘宝上的 Json 数据 - 回复 "macrolen" 的问题

macrolen 给了这样一些数据, 说是用淘宝的 API 获取的 JSON 数据, 让我帮助解析:

{"items_search_response":{"item_search":{"item_categories":{"item_category":[{"category_id":150708,"count":66},{"category_id":50002480,"count":93},{"category_id":50006247,"count":164},{"category_id":50012579,"count":19518},{"category_id":50012018,"count":92},{"category_id":150704,"count":10527},{"category_id":150705,"count":226},{"category_id":150706,"count":604},{"category_id":50005050,"count":2900},{"category_id":50011418,"count":94},{"category_id":50012587,"count":6711},{"category_id":50012584,"count":14661},{"category_id":50011150,"count":3058},{"category_id":50008194,"count":72},{"category_id":50010259,"count":348},{"category_id":50008681,"count":251},{"category_id":50003774,"count":252},{"category_id":50003775,"count":7022},{"category_id":150701,"count":802},{"category_id":50012010,"count":134},{"category_id":50008202,"count":68},{"category_id":3412,"count":1125},{"category_id":50005787,"count":127},{"category_id":50002928,"count":158},{"category_id":50014945,"count":113},{"category_id":50010614,"count":2120},{"category_id":140908,"count":122},{"category_id":50003781,"count":349},{"category_id":50008734,"count":755},{"category_id":50002887,"count":114},{"category_id":50003853,"count":252},{"category_id":50005266,"count":2490},{"category_id":50003327,"count":1326},{"category_id":50008169,"count":562},{"category_id":1205,"count":202},{"category_id":50008096,"count":66},{"category_id":50005729,"count":752},{"category_id":50012166,"count":176},{"category_id":1512,"count":107960},{"category_id":111005,"count":330}]},"items":{"item":[{"cid":150701,"delist_time":"2010-01-20 19:07:23","iid":"6b1589a0bbcd485c32e3c41280dbe7a1","location":{"city":"襄樊","state":"湖北"},"nick":"勤劳的蚂蚁","pic_url":"http://img05.taobaocdn.com/bao/uploaded/i5/T1ER4mXfNhXXbBnmZV_022002.jpg","post_fee":"10.00","price":"0.01","title":"诺基亚 <span class=H>Nokia</span> 5800 5802原配挂绳  拨片","type":"fixed"},{"cid":111005,"delist_time":"2010-01-27 22:18:15","iid":"70fe721c9586bba64003071cc91fbf76","location":{"city":"武汉","state":"湖北"},"nick":"whjctx","pic_url":"http://img04.taobaocdn.com/bao/uploaded/i4/T13IJlXa4SF0O8eUk8_101815.jpg","post_fee":"0.00","price":"0.01","title":"诺基亚 三星<span class=H>NOKIA</span> S60赛班系统证书/数字证书制作/赛班证书制作/","type":"fixed"},{"cid":50005981,"delist_time":"2010-01-28 14:25:13","iid":"66367f673e58f63878ea69736fcd2f5f","location":{"city":"广州","state":"广东"},"nick":"habit5200","pic_url":"http://img06.taobaocdn.com/bao/uploaded/i6/T1mylkXlH2AJNeW1s1_041006.jpg","post_fee":"0.00","price":"0.01","title":"<span class=H>NOKIA</span> N97待机图片","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-28 21:00:00","iid":"2c71fb0ca2dba9f3ae5c01f12f98ed73","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img07.taobaocdn.com/bao/uploaded/i7/T1p1lrXiFxXXbZq0o2_043505.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> 5530 触屏手机 屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-29 00:00:00","iid":"226514eb9283ec20695043e27c1a60e8","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img02.taobaocdn.com/bao/uploaded/i2/T1MuprXd8vXXa5Dwc1_040919.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> E63专用智能手机 屏幕保护膜/贴膜/屏保膜非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-30 00:00:00","iid":"e0b8a84070297bfe6179e9d2acebaae3","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1Ge8rXe0vXXazcT7Y_030713.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> N82 直板手机专用屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-30 09:00:00","iid":"bf433c0ca19c9070635ad46628f367eb","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img04.taobaocdn.com/bao/uploaded/i4/T13u0rXX0yXXXZdbM3_045925.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> 8800A 滑盖手机 屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-30 15:00:00","iid":"1f0fdb5181209632623eb0e3b6c84e5f","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1nvxrXnxlXXa.hmZ2_045316.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> N78 直板手机专用屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-31 00:00:00","iid":"4c255a73b0b4ea8f8c06655214265b45","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img06.taobaocdn.com/bao/uploaded/i6/T1zvtrXaFnXXXFOEQ2_045546.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> E66专用滑盖手机 屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50012587,"delist_time":"2010-01-31 09:00:00","iid":"a88b1bfec52d12e4d7b210d73d6911ff","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img03.taobaocdn.com/bao/uploaded/i3/T1FvtrXoVmXXXPrgE3_050142.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> N96 双向滑盖手机 屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50003853,"delist_time":"2010-01-31 16:28:05","iid":"77fab0d06ff871131c594c002f839cac","location":{"city":"合肥","state":"安徽"},"nick":"baoyuanfei","pic_url":"http://img08.taobaocdn.com/bao/uploaded/i8/T1hv0qXb0yXXcTmX.._111221.jpg","post_fee":"0.00","price":"0.01","title":"<span class=H>NOKIA</span>手机防骚扰软件,特价!只赚信誉不赚钱!","type":"fixed"},{"cid":50012587,"delist_time":"2010-02-01 09:00:00","iid":"38fc1c7bcc12bfe0e7ea3baa819490d1","location":{"city":"广州","state":"广东"},"nick":"mostmoral","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1pxtrXgFdXXbVNIHa_120423.jpg","post_fee":"8.00","price":"0.01","title":"诺基亚<span class=H>NOKIA</span> N95 8GB 滑盖手机 屏幕保护膜/贴膜/屏保膜 非镜面膜","type":"fixed"},{"cid":50002480,"delist_time":"2010-01-19 14:13:27","iid":"341c2ba20d491fe92af6e48dbf3b6590","location":{"city":"秦皇岛","state":"河北"},"nick":"zhouyunzhe520","pic_url":"http://img02.taobaocdn.com/bao/uploaded/i2/T1EjXlXfWpIJOuh2HX_084849.jpg","post_fee":"0.00","price":"0.10","title":"【1小时】<span class=H>NOKIA</span> E66手机证书制作 塞班 17最高权限","type":"fixed"},{"cid":50011150,"delist_time":"2010-01-20 00:10:57","iid":"2ec4d847b7d70a331d6ba59cb7ba6da2","location":{"city":"温州","state":"浙江"},"nick":"星星亮星","pic_url":"http://img07.taobaocdn.com/bao/uploaded/i7/T1WfRgXbXBXXbIjtEW_022836.jpg","post_fee":"0.00","price":"0.10","title":"不干胶 标签/不干胶 印刷/不干胶 贴纸/防伪标签/<span class=H>NOKIA</span>防伪标","type":"fixed"},{"cid":50011150,"delist_time":"2010-01-20 14:23:52","iid":"b221417baa9905dd7c7181b8b0cde710","location":{"city":"温州","state":"浙江"},"nick":"星星亮星","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1zMXgXi4AXXcVWJgW_022806.jpg","post_fee":"0.00","price":"0.10","title":"不干胶 标签/不干胶 印刷/不干胶 贴纸/防伪标签/<span class=H>NOKIA</span>防伪标","type":"fixed"},{"cid":50011150,"delist_time":"2010-01-20 18:46:54","iid":"1e856e0507266ad417768ff397f5e993","location":{"city":"温州","state":"浙江"},"nick":"星星亮星","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1EgtgXeJzXXXjkGAW_022444.jpg","post_fee":"0.00","price":"0.10","title":"激光不干胶 标签/不干胶 印刷/不干胶 贴纸/激光标签/<span class=H>NOKIA</span>防伪标","type":"fixed"},{"cid":50003327,"delist_time":"2010-01-20 23:27:13","iid":"61412071aaeeb580f03240987ba31e33","location":{"city":"南京","state":"江苏"},"nick":"小不点名绣坊","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1vkxrXdpbXXcN8yZ8_070829.jpg","post_fee":"5.00","price":"0.10","title":"<span class=H>NOKIA</span>原装数据线 包原适用大部分型号5800,E71,5530,N97,N86等","type":"fixed"},{"cid":50005980,"delist_time":"2010-01-21 09:43:00","iid":"f40ee96c548b3adbc38a080c39e33130","location":{"city":"上海","state":"上海"},"nick":"seazhang8421","pic_url":"http://img01.taobaocdn.com/bao/uploaded/i1/T1WZxnXlJkXXXQwcvX_114450.jpg","post_fee":"0.00","price":"0.10","title":"<span class=H>NOKIA</span>彩铃--等爱的玫瑰","type":"fixed"},{"cid":50005980,"delist_time":"2010-01-21 09:43:00","iid":"443dc0516f48677c20c4801e47d6732c","location":{"city":"上海","state":"上海"},"nick":"seazhang8421","pic_url":"http://img02.taobaocdn.com/bao/uploaded/i2/T18c8hXdeW_tKFc.75_060404.jpg","post_fee":"0.00","price":"0.10","title":"<span class=H>NOKIA</span>彩铃--我爱你塞北的雪","type":"fixed"},{"cid":50011150,"delist_time":"2010-01-21 17:02:14","iid":"08e0a507c9dceb327bb66a40da1cfab2","location":{"city":"成都","state":"四川"},"nick":"cdzysd","pic_url":"http://img08.taobaocdn.com/bao/uploaded/i8/T125JlXbVJItP8_w73_050214.jpg","post_fee":"10.00","price":"0.10","title":"<span class=H>NOKIA</span>挂绳","type":"fixed"}]}},"total_results":189678}}

把这些数据保存在: c:\temp\json.txt; 然后在窗体上放一个 Memo 和四个 Button ...


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses SuperObject;
var jo: ISuperObject;

//载入并建立对象
procedure TForm1.FormCreate(Sender: TObject);
const
  JsonPath = ‘c:\temp\json.txt‘;
begin
  Assert(FileExists(JsonPath), ‘文件不存在‘);
  with TStringList.Create do
  begin
    LoadFromFile(‘c:\temp\json.txt‘);
    jo := SO(Text);
    Free;
  end;
end;

//按格式查看所有
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := jo.AsJSon(True, False);
end;

//查看: items_search_response.item_search.item_categories
procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Text := jo[‘items_search_response.item_search.item_categories‘].AsJSon(True, False);
end;

//查看: items_search_response.item_search.items
procedure TForm1.Button3Click(Sender: TObject);
begin
  Memo1.Text := jo[‘items_search_response.item_search.items‘].AsJSon(True, False);
end;

//遍历 items_search_response.item_search.items.item 数组中的指定元素
procedure TForm1.Button4Click(Sender: TObject);
var
  ja: TSuperArray;
  i: Integer;
begin
  ja := jo[‘items_search_response.item_search.items.item‘].AsArray;
  Memo1.Clear;
  for i := 0 to ja.Length - 1 do
  begin
    Memo1.Lines.Add(ja.O[i].Format(‘%cid%; %location.state%; %location.city%‘));
  end;
end;

end.


另外 SuperObject 当前的最新版本是: SuperObjectv1.2.3, 还没有测试它新增的功能, 不过我这个是用它做的.

时间: 2024-10-09 13:53:39

用 SuperObject 解析淘宝上的 Json 数据 - 回复 "macrolen" 的问题的相关文章

你刚在淘宝上买了一件衣服---详细解析技术流程(淘宝首页显示一个页面的过程)

声明:文章是之前在网络中看到并保存在电脑里的文档,原地址也无从找到.在此声明.向互联网工程师致敬! 你发现快要过年了,于是想给你的女朋友买一件毛衣,你打开了www.taobao.com.这时你的浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.不过首先你会发现,你在不同的地区或者不同的网络(电信.联通.移动)的情况下,转换后的IP地址很可能是不一样的,这首先涉及到负载均衡的第一步,通过DNS解析域名时将你的访问分配到不同的入口,同时尽可能保证你所访问的入口是所有入口中可能

技术普及帖:你刚才在淘宝上买了一件东西

你发现快要过年了,于是想给你的女朋友买一件毛衣,你打开了www.taobao.com.这时你的浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.不过首先你会发现,你在不同的地区或者不同的网络(电信.联通.移动)的情况下,转换后的IP地址很可能是 不一样的,这首先涉及到负载均衡的第一步,通过DNS解析域名时将你的访问分配到不同的入口,同时尽可能保证你所访问的入口是所有入口中可能较快的一个 (这和后文的CDN不一样). 你通过这个入口成功的访问了www.taobao.com的

你刚才在淘宝上买了一件东西【技术普及贴】

原文链接:http://blog.renren.com/share/1008228562/11138179294 你发现快要过年了,于是想给你的女朋友买一件毛衣,你打开了www.taobao.com.这时你的浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.不过首先你会发现,你在不同的地区或者不同的网络(电信.联通.移动)的情况下,转换后的ip地址很可能是不一样的,这首先涉及到负载均衡的第一步,通过DNS解析域名时将你的访问分配到不同的入口,同时尽可能保证你所访问的入口是

[转载]你刚才在淘宝上买了一件东西

你发现快要过年了,于是想给你的女朋友买一件毛衣,你打开了www.taobao.com.这时你的浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.不过首先你会发现,你在不同的地区或者不同的网络(电信.联通.移动)的情况下,转换后的ip地址很可能是不一样的,这首先涉及到负载均衡的第一步,通过DNS解析域名时将你的访问分配到不同的入口,同时尽可能保证你所访问的入口是所有入口中可能较快的一个(这和后文的CDN不一样). 你通过这个入口成功的访问了www.taobao.com的实际

爬虫实战【8】Selenium解析淘宝宝贝-获取多个页面

作为全民购物网站的淘宝是在学习爬虫过程中不可避免要打交道的一个网站,而是淘宝上的数据真的很多,只要我们指定关键字,将会出现成千上万条数据. 今天我们来讲一下如何从淘宝上获取某一类宝贝的信息,比如今天我们以"手机"作为关键词,举个例子. 分析页面的源代码 [插入图片,淘宝手机页面示意] 上面是搜索框,下面显示了很多宝贝信息,最下面是翻页的控制按钮. [插入图片,淘宝手机页面源代码] 我们看一下这个页面的源代码,发现都是一些js,还提示了要运行脚本才能显示. 难道宝贝也是Ajax加载的?我

亲身经历揭露淘宝上主板交换的陷阱

转:亲身经历揭露淘宝上主板交换的陷阱 淘宝上现在很多主板交换,一般300钱左右,坏板换成良品板,各种品牌,各种型号的主板都可以交换,初一看,挺合算,维修一下至少也是100多200多钱,还不如直接交换,方便快捷,殊不知这种交换其实就是个真正的陷阱. 亲身经历一.三星主板,发过去,被告之不能交换,淘宝JS说随便还我一块,然后东拖西拖,时间长了,也就不了了之. 亲身经历二.THINKPAD SL410主板,也是发过去,然后被告之不能交换,发回来是另一块,显卡.显存都被动过的报废板,因为收货的时候没注意

转::iOS 仿淘宝,上拉进入详情页面

今天做的主要是一个模仿淘宝,上拉进入商品详情的功能,主要是通过 tableView 与 webView 一起来实现的,当然也可根据自己的需要把 webView 替换成你想要的 1 // 2 // ViewController.m 3 // 仿淘宝,上拉进入详情 4 // 5 // Created by Amydom on 16/11/22. 6 // Copyright ? 2016年 Amydom. All rights reserved. 7 // 8 9 #import "ViewCont

【Python3 爬虫】14_爬取淘宝上的手机图片

现在我们想要使用爬虫爬取淘宝上的手机图片,那么该如何爬取呢?该做些什么准备工作呢? 首先,我们需要分析网页,先看看网页有哪些规律 打开淘宝网站http://www.taobao.com/ 我们可以看到左侧是主题市场,将鼠标移动到[女装/男装/内衣]这一栏目,我们可以看到更细类的展示 假如我们现在需要爬取[羽绒服],那么我们进入到[羽绒服]衣服这个界面 此时查看浏览器地址,我们可以看到 网址复制到word或者其他地方会发生url转码 我们可以选中[羽绒服模块的第1,2,3页进行网址对比],对比结果

Android解析中国天气网的Json数据

在Android开发中.一般的APP都是通过获取server端的数据来更新UI.从server获取到的数据能够是Json.它的数据量要比XML要小,这里解析中国天气网上获取的数据,尽管已经不再更新了.但用来学习还是能够的.为了方便我直接到数据通过txt保存到本地,它的数据能够通过这个页面获取:http://m.weather.com.cn/data/101280601.html 文件夹结构 事实上解析也非常easy.关键代码 private void json3() { InputStream