最近学习MongoDB,需要获取大量Json在线数据,例如: http://media.mongodb.org/zips.json
此处使用c#,直接给出代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://media.mongodb.org/zips.json");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream ResStream = response.GetResponseStream();
Encoding encoding = Encoding.Default;
StreamReader streamReader = new StreamReader(ResStream, encoding);
using (FileStream fileStream = File.Create("test.json"))
{
byte[] bytes = new UTF8Encoding(true).GetBytes(streamReader.ReadToEnd());
fileStream.Write(bytes, 0, bytes.Length);
}
仅仅记录下来,方便以后使用