這範例是抓取youtube影片的資訊
透過youtube api提供的json來解析取得想要的data
這邊是直接把json轉成dynamic
個人比較喜歡這樣....因為我真的搞不懂.net的Dictionary還是甚麼List的0rz
dynamic寫法就很像php
反正你知道他的json長甚麼樣子再下去寫就好
也不用為此創一個物件去弄些543麻煩要命
所以我討厭寫.net.......php這邊只要json_decode($xxx)就可以把他轉成陣列
真的不用幾秒的時間....
c#這邊則是要透過一堆物件做些奇奇怪怪的事才完成
雖然人家物件導向比較屌.....
但我就是懶....還是prefer用php簡單coding就可達成所要的結果
---------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string url = "http://gdata.youtube.com/feeds/api/videos/UlNO5CpVbhk?v=2&alt=json";
var webRequest = WebRequest.Create(url);
using (var response = webRequest.GetResponse())
using (var content = response.GetResponseStream())
using (var reader = new StreamReader(content))
{
var strContent = reader.ReadToEnd();
JavaScriptSerializer jss = new JavaScriptSerializer();
dynamic d = jss.Deserialize<dynamic>(strContent);
Label1.Text = d["entry"]["yt$statistics"]["viewCount"].ToString();
}
}
}
---------------------------------------------------------
Hiển thị các bài đăng có nhãn c#. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn c#. Hiển thị tất cả bài đăng
Chủ Nhật, 24 tháng 2, 2013
Chủ Nhật, 13 tháng 1, 2013
Thứ Sáu, 11 tháng 1, 2013
LINQ ~ where like
x = (from r in ctx.xxxxxx
where r.name.Contains("adasdad")
select (new KeyValuePair
).ToDictionary(t => t.Key, t => t.Value);
reference
http://stackoverflow.com/questions/5374481/like-operator-in-linq
C# ~ is request exists
if (Request.QueryString["xxxx"] != null)
{
// it exists
}
else
{
// it doesn't
}
reference
http://www.velocityreviews.com/forums/t107127-querystring-exists.html
Thứ Sáu, 9 tháng 11, 2012
LINQ ~ where clause example
dynamic labor = ctx.Qoo.Where(l => l.xxxID== xxxID).Select(l => l).ToList().Select(l =>
{
dynamic aaa = new ExpandoObject();
aaa.ooo= l.ooo;
aaa.yyy= l.yyy;
aaa.hhh= l.hhh;
return aaa;
}).ToArray();
reference
http://stackoverflow.com/questions/8663897/why-is-linq-wherepredicate-first-faster-than-firstpredicate
{
dynamic aaa = new ExpandoObject();
aaa.ooo= l.ooo;
aaa.yyy= l.yyy;
aaa.hhh= l.hhh;
return aaa;
}).ToArray();
reference
http://stackoverflow.com/questions/8663897/why-is-linq-wherepredicate-first-faster-than-firstpredicate
Thứ Tư, 4 tháng 7, 2012
PDF Sharp ~ 亂碼問題
這問題是在對方server輸出pdf
出現亂碼的問題
但由於我們都跑得很正常
所以就推估應該是字型問題
嘗試改了幾個字型確實可以working~~
遇到這問題的就試試看囉
一開始的設定是
而人家的Server 2008 R2跑不出來
我們是Win7才如此推估
好在確實是這問題XD
出現亂碼的問題
但由於我們都跑得很正常
所以就推估應該是字型問題
嘗試改了幾個字型確實可以working~~
遇到這問題的就試試看囉
Style style = document.Styles[StyleNames.Normal];
style.Font.Name = "微軟正黑體";
style.Font.Name = "微軟正黑體";
一開始的設定是
style.Font.Name = "Arial Unicode MS";
而人家的Server 2008 R2跑不出來
我們是Win7才如此推估
好在確實是這問題XD
Thứ Sáu, 22 tháng 6, 2012
c# ~ ashx get post data
string reportTypeKey = context.Request.Params["reportTypeKey"].ToString();
reference
http://stackoverflow.com/questions/3991894/ashx-c-sharp-for-each-loop-on-post-vars
C# ~ delete file
protected void deleteFile(string fileName) {
string path = Server.MapPath("~/bulletin/");
try {
System.IO.File.Delete(path + fileName);
} catch (System.IO.IOException e) {
return;
}
}
string path = Server.MapPath("~/bulletin/");
try {
System.IO.File.Delete(path + fileName);
} catch (System.IO.IOException e) {
return;
}
}
reference
http://msdn.microsoft.com/zh-tw/library/cc148994.aspx
Thứ Năm, 21 tháng 6, 2012
c# ~ fileupload save to relative path
Server.MapPath("~/Images/Logos/" + uploadedFileName);
http://stackoverflow.com/questions/5816699/file-uploading-using-server-mappath-and-fileupload-saveas
http://stackoverflow.com/questions/5816699/file-uploading-using-server-mappath-and-fileupload-saveas
Thứ Năm, 26 tháng 4, 2012
C# ~ output Date from DateTime
txtFrom.Text = string.Format("{0:yyyy/M/dd}", template.ValidDateTime);
reference
http://www.dotblogs.com.tw/skyline0217/archive/2011/01/26/21047.aspx
Thứ Bảy, 21 tháng 4, 2012
C# ~ rtrim TrinEnd
作陣列輸出時可能會用個,做區隔
到最後一個輸出的時候都要把多餘的,拿掉
以下是寫法XD
到最後一個輸出的時候都要把多餘的,拿掉
以下是寫法XD
char[] trimchars = { ',', ' ' };
string DiagnosiseText = "";
List<string> DiagnosiseNames = Referral.DiagnosisesNames;
DiagnosiseNames.ForEach(delegate(string i) {
DiagnosiseText += i + ", ";
});
SetReportValue("DiagnoseName", DiagnosiseText.TrimEnd(trimchars));
Thứ Sáu, 20 tháng 4, 2012
C# ~ List example
List<int> ProcessStatusIds = Referral.ReferralSheet_ProcessStatusIDs;
List<string> ProcessStatusOtherTexts = Referral.ReferralSheet_ProcessStatusOtherTexts;
ProcessStatusIds.ForEach(delegate(int i) {
if (i <= 7) {
SetReportValue("ProcessStatusID" + i, CheckString);
switch (i) {
case 2:
case 3:
case 6:
case 7:
if (!String.IsNullOrEmpty(ProcessStatusOtherTexts[i])) {
SetReportValue("ProcessStatusOtherTexts" + i, ProcessStatusOtherTexts[i]);
}
break;
}
}
});
http://msdn.microsoft.com/en-us/library/bwabdf9z.aspx
Đăng ký:
Bài đăng (Atom)
