沒有什麼特別之處[CDC]和JSON - 它應該只是工作 - 看下面的代碼。嘗試將其與您的網站進行比較,包括網絡跟蹤(如Fiddler等工具中所見),並查看有何不同。
public class StackOverflow_15343502
{
const string JSON = "[{\"key1\": 12, \"key2\": \"ab\"}, {\"key1\": 10, \"key2\": \"bc\"}]";
public class MyDC
{
public int key1 { get; set; }
public string key2 { get; set; }
public override string ToString()
{
return string.Format("[key1={0},key2={1}]", key1, key2);
}
}
[CollectionDataContract]
public class MyCDC : List<MyDC> { }
[ServiceContract]
public class Service
{
[WebGet]
public Stream GetData()
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
return new MemoryStream(Encoding.UTF8.GetBytes(JSON));
}
}
[ServiceContract]
public interface ITest
{
[WebGet(ResponseFormat = WebMessageFormat.Json)]
MyCDC GetData();
}
public static void Test()
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
host.Open();
Console.WriteLine("Host opened");
WebChannelFactory<ITest> factory = new WebChannelFactory<ITest>(new Uri(baseAddress));
ITest proxy = factory.CreateChannel();
var result = proxy.GetData();
Console.WriteLine(string.Join(", ", result));
((IClientChannel)proxy).Close();
factory.Close();
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}
請告訴你如何試圖解析它,它可能是你只是稍微偏離並在這裏多餘的眼睛可以告訴你的剩下的路 – curtisk 2013-03-11 17:18:03