顯示具有 JSON 標籤的文章。 顯示所有文章
顯示具有 JSON 標籤的文章。 顯示所有文章

2015-04-06

Google App Engine memcache 測試

環境:

  • Google App Engine - 1.9.18
  • Python-2.7

# -*- coding: utf-8 -*-
#!/usr/bin/env python2.7
import webapp2
import urllib2
import json

from google.appengine.api import memcache
from google.appengine.ext.webapp.util import run_wsgi_app
   
class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
       
        r = urllib2.urlopen('http://mis.twse.com.tw/stock/api/getIndustry.jsp')
        j = json.loads(r.read())
        for n in range(0,len(j['tse'])):
            memcache.add(key=j['tse'][n]['code'], value=j['tse'][n]['name'], namespace='tse')
           
        for n in range(0,len(j['otc'])):
            memcache.add(key=j['otc'][n]['code'], value=j['otc'][n]['name'], namespace='otc')
       
        self.response.out.write(memcache.get(key='01', namespace='tse'))
        self.response.out.write(memcache.get(key='01', namespace='otc'))

2015-02-21

Delphi 讀取證券交易所股票資訊JSON格式

環境:

  • Win7
  • Delphi XE4

uses IdHTTP, Data.DBXJSON;
...
...


procedure TForm1.Button1Click(Sender: TObject);
var
  H: TIdHTTP;
  JSON: String;
  JO: TJSONObject;
  JV: TJSONValue;
  JP: TJSONPair;
begin
  H:=TIdHTTP.Create(nil);
  H.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)';
  JSON:=H.Get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_3673.tw');
  JO := TJSONObject.ParseJSONValue(JSON) as TJSONObject;
  JP := JO.Get(0);
  ShowMessage(JP.ToString);
  ShowMessage(JP.JsonString.Value);
  JV:=(JP.JsonValue as TJSONArray).Get(0);
  ShowMessage((JV as TJSONObject).Get('n').JsonValue.Value);
  FreeAndNil(JO);
  FreeAndNil(H);
end;