0
很簡單的事情要做,我不能因爲某種原因找出這一個。我有一個模擬的JSON文件看起來像這樣:解析一個JSON文件並得到「無效的JSON基元: 0 0 0 0」
{
"AccountId":"XXXXXXXXX",
"UAN":"PE3458234758345",
"BillingName":"John Smith",
"BillingAddress": {
"Address1":"701 First Ave.",
"Address2":"test",
"City":"Philadelphia",
"State":"PA",
"Zip:":"19147"
},
"ServiceStartDate":"5/1/2012",
"PromoCode":"0056",
"PartnerCode":"AAL",
"MemberNumber":"0000001",
"Invoices":[
{
"Amount":"113.78",
"Date":"6/1/2012",
"Usage":"3143"
},
{
"Amount":"123.56",
"Date":"7/1/2012",
"Usage":"4561"
},
{
"Amount":"105.23",
"Date":"8/1/2012",
"Usage":"5454"
}
],
"Expected":[
{
"AwardCreation":"true",
"AwardAmount":"500",
"AwardUnits":"usd",
"AwardDate":"today()"
}
]
}
而且我需要從這個創建一個動態的對象,因爲這每一個測試樣機的運行時間可以改變。我已經嘗試了自定義解串器的注意in this solutio還有.NET 4.0 System.Web.Helpers並在這兩種情況下我結束了:
Invalid JSON primitive: \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...
目前我的工作測試:
var json = new StringBuilder();
using (var fs = File.Open(@"c:\users\bryan\Desktop\test2.json", FileMode.Open))
{
var byteArray = new byte[1024];
var tempString = new UTF8Encoding(true);
while (fs.Read(byteArray, 0, byteArray.Length) > 0)
{
json.Append(tempString.GetString(byteArray));
}
}
var dynamicObject = Json.Decode(json.ToString());
Assert.IsNotNull(dynamicObject);
我沒有線索,我猜這是格式?我已經從json文件中刪除了所有內容(意思是一條巨大的線),並且我得到了同樣的結果。奇怪的是,當我使用Newtonsoft.Json時,我沒有收到錯誤信息,但動態對象只是AccountId字符串,沒有其他字符。
是的,我錯過了樹林通過樹木好吧。感謝深夜的幫助。 – BryanGrimes 2012-08-15 01:43:50