首页 > 代码库 > C#百度图片识别API调用返回数据包解析
C#百度图片识别API调用返回数据包解析
百度图片识别api接口
public static JObject GeneralBasic(string apikey,string secretkey,string path) { var client = new Baidu.Aip.Ocr.Ocr(apikey, secretkey); var image = File.ReadAllBytes(path); // 通用文字识别 var result = client.GeneralBasic(image, null); return result; }
调用,方法,以及返回json 解析
private void txbupload_Click(object sender, EventArgs e) { string apikey = txbapikey.Text; string secretkey = txbsercetkey.Text; string imagepath = txbpic.Text+ "\\yancaoxuke.jpg"; JObject result = OcrDemo.GeneralBasic(apikey, secretkey, imagepath); var txts = (from obj in (JArray)result.Root["words_result"] // let phrase = (JObject)obj["phrase"] select (string)obj["words"]); foreach (var r in txts) Console.WriteLine(r); }
包结构:
log_id:3544105182,words_result_num:15,words_result:[ { "words": "XX专卖零售许可证" }, { "words": "许可证号xxx" }, { "words": "XX有限公司" }, { "words": "法定代表人xx" }, { "words": "(负责人)" }, { "words": "320507217865" }, { "words": "企业型" }, { "words": "有限责任公司" }, { "words": "经營场xx室" }, { "words": "卷烟,雪茄烟" }, { "words": "许可范围" }, { "words": "xxxx公司" }, { "words": "供货单位" }, { "words": "有效期服自" },
参考:1
const string s = "{\"result\" : \"ok\",\"tuc\" : [ {\"authors\" : [ 13 ],\"meaningId\" : 2397164096556578585,\"phrase\" : {\"text\" : \"机场\",\"language\" : \"zho\" }},{\"authors\" : [ 3266 ],\"meaningId\" : 1269040436618011315,\"phrase\" : {\"text\" : \"機場\",\"language\" : \"zho\"}}]}"; var root = JObject.Parse(s); var txts = (from obj in (JArray)root["tuc"] let phrase = (JObject)obj["phrase"] select (string)phrase["text"]); foreach (var r in txts) Console.WriteLine(r);
2:
const string s = "{\"result\" : \"ok\",\"tuc\" : [ {\"authors\" : [ 13 ],\"meaningId\" : 2397164096556578585,\"phrase\" : {\"text\" : \"机场\",\"language\" : \"zho\" }},{\"authors\" : [ 3266 ],\"meaningId\" : 1269040436618011315,\"phrase\" : {\"text\" : \"機場\",\"language\" : \"zho\"}}]}"; var root = JObject.Parse(s); var txts = (from obj in (JArray)root["tuc"] select (string)obj["phrase"]["text"]); foreach (var r in txts) Console.WriteLine(r);
如果你从未使用过 json.net,那么可以看这个帖子开始:http://blog.csdn.net/leftfist/article/details/38687745
http://bbs.csdn.net/topics/390869393
C#百度图片识别API调用返回数据包解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。