如何使用C#解析语言api的响应 [英] How to parse response of linguistic api using C#

查看:56
本文介绍了如何使用C#解析语言api的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Linguistic API

我已经解析了 string 使用
{
id 22a6b758-420f-4745-8a3c-46835a67c0d2
语言:[
en
],
kind Constituency_Tree
规范 PennTreebank3
implementation SplitMerge
},

和API响应
{
analyzerId 22a6b758-420f-4745-8a3c-46835a67c0d2
结果:[
(TOP(S(NP(PRP I))( VP(VBP爱)(NP(PRP $ my)(NNP印度)))))
]
}

现在我想生成一个所有NP列表或所有VBP 使用 C#。
任何库/ C#代码可用于实现列表来自 响应。





< b>我尝试了什么:



i在C#中找不到任何合适的示例或库用于解析

解决方案

my)(NNP India)))))
]
}

现在我想生成一个All列表NP或所有VBP 使用 C#。
任何可用于实现的库/ C#代码< span class =code-keyword>此列表来自 响应。





我尝试了什么:



i还没有在C#中找到了适合此解析的合适示例或库


所以您的数据响应格式似乎是JSON。在谷歌中解析JSON的简单搜索揭示了一个巨大的结果。我不知道你对图书馆的偏好是什么,但我建议使用JSON.net/newtonsoft库。



使用JSON.net很简单,你可以拿你正在尝试阅读的json回复,使用网站 json2csharp - 从json生成c#类 [ ^ ]它将生成多个C#类供您用于序列化/反序列化您的json。



例如:



 {
analyzerId 22a6b758-420f-4745- 8a3c-46835a67c0d2
result:[
(TOP(S(NP(PRP I))(VP(VBP爱)(NP(PRP


我) (NNP India)))))
]
}





使用json2csharp生成class



  public   class  RootObject 
{
public string analyzerId {获得; set ; }
public List< string>结果{获取; set ; }
}





从那里使用JSON.net所有你要做的就是做



  var  response =  @ < span class =code-string>这是你的json字符串; 


string json = @ {
analyzerId 22a6b758-420f -4745-8a3c-46835a67c0d2
result :[
(TOP(S(NP(PRP I))(VP(VBP爱)(NP(PRP

I am using Microsoft Linguistic API

I have parsed a string Using
{
    "id": "22a6b758-420f-4745-8a3c-46835a67c0d2",
    "languages": [
      "en"
    ],
    "kind": "Constituency_Tree",
    "specification": "PennTreebank3",
    "implementation": "SplitMerge"
  },

and API response is 
{
    "analyzerId": "22a6b758-420f-4745-8a3c-46835a67c0d2",
    "result": [
      "(TOP (S (NP (PRP I)) (VP (VBP love) (NP (PRP$ my) (NNP India)))))"
    ]
  }

Now here i wants to generate a list of All NP or all VBP using C#.
There is any library  /  C# code available to achieve this list from this response.



What I have tried:

i have not found any suitable example or library in C# for this parsing

解决方案

my) (NNP India)))))" ] } Now here i wants to generate a list of All NP or all VBP using C#. There is any library / C# code available to achieve this list from this response.



What I have tried:

i have not found any suitable example or library in C# for this parsing


So your data response format appears to be JSON. A simple search of parsing JSON in google reveals a bajillion results. I don't know what your preference is in terms of libraries but i would suggest using JSON.net/newtonsoft library.

Using JSON.net is easy, you can take your json response you are trying to read, use the website json2csharp - generate c# classes from json[^] and it will generate multiple C# classes for you to use for serializing/deserializing your json.

Example:

{
    "analyzerId": "22a6b758-420f-4745-8a3c-46835a67c0d2",
    "result": [
      "(TOP (S (NP (PRP I)) (VP (VBP love) (NP (PRP


my) (NNP India)))))" ] }



Using json2csharp generates the class

public class RootObject
{
    public string analyzerId { get; set; }
    public List<string> result { get; set; }
}



From there using JSON.net all you have to do is do

var response = @"this is your json string here";


string json = @"{
    "analyzerId": "22a6b758-420f-4745-8a3c-46835a67c0d2",
    "result": [
      "(TOP (S (NP (PRP I)) (VP (VBP love) (NP (PRP


这篇关于如何使用C#解析语言api的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆