天气预报
var astream : tmemorystream; sStream : TStringStream; jv : TJSONValue; begin astream := tmemorystream.Create; sStream := TStringStream.Create( '', tencoding.UTF8 ); self.NetHTTPClient1.Get( 'http://www.weather.com.cn/adat/sk/101010100.html', astream ); sStream.CopyFrom( astream, astream.Size ); self.Caption := sStream.Size.ToString( ); Memo1.Text := sStream.DataString; jv := TJSONObject.ParseJSONValue( Memo1.Text ) as TJSONValue; self.Caption := jv.GetValue( 'weatherinfo', '' ); freeandnil( sStream ); freeandnil( astream ); end;
{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"9","WD":"西南风","WS":"2级","SD":"22%","WSE":"2","time":"10:35","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暂无实况","qy":"1015"}}
TJSONObject *jo = (TJSONObject*) TJSONObject::ParseJSONValue(this->Memo6->Text); jo = (TJSONObject*)jo->Get("weatherinfo")->JsonValue; Memo6->Lines->Add(((TJSONPair*) jo->Get("city"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("cityid"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("temp"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("WD"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("WS"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("SD"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("WSE"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("time"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("isRadar"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("Radar"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("njd"))->JsonValue->Value()); Memo6->Lines->Add(((TJSONPair*) jo->Get("qy"))->JsonValue->Value());