[英]How to read the data from json file and return as string or object in angularJS?
[英]AngularJS how return a string instead of Json object
我使用angularjs從Web服務獲取字符串。 該字符串實際上是base64 pdf文件。
public string Get(int id)
{
var bytes = File.ReadAllBytes(@"C:\test.pdf");
var content = Convert.ToBase64String(bytes);
return content;
}
Angularjs返回了一個像這樣的數組:
{“ 0”:“ \\”“,” 1“:” J“,” 2“:” V“,” 3“:” B“,” 4“:” E“ ...}
但我需要這樣的完整字符串:“ JVBE ...”
我試圖找到一種獲取完整字符串而不是數組格式的方法,但是我什么也沒找到。
你知道如何處理嗎?
謝謝!
卡琳
看來您是從.Net MVC的Web API返回數據。 你可以做
public object Get(int id)
{
var bytes = File.ReadAllBytes(@"C:\test.pdf");
var content = Convert.ToBase64String(bytes);
return new {value = content};
}
由於無法將字符串轉換為JSON。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.