How to get the value of an Odata JSON object and convert it to string?

-2

After accessing WCF, I get the following response:

{
    "odata.metadata": "http://luiz-note64/WcfOper/WcfOperDataService.svc/$metadata#Operacoes&$select=IdOperacao",
    "value": [
        {
            "IdOperacao": "4234340"
        }
    ]
}

How do I extract the value of IdOperacao to a string from the answer?

    
asked by anonymous 09.10.2015 / 22:27

1 answer

2

Here is the Solution:

The WCF call response:

{
    "odata.metadata": "http://luiz-note64/WcfOper/WcfOperDataService.svc/$metadata#Operacoes&$select=IdOperacao",
    "value": [
        {
            "IdOperacao": "4234340"
        }
    ]
} 

Below the Call code and the conversion of the "IdOperation" field into     string:

Uri xuri = new Uri(uri, "/WcfOper/WcfOperDataService.svc/Operacoes?&$format=json&$filter=OperGuid%20eq%2‌​0"+ "'" + objLocal.OperGuid + "'" + "&$select=IdOperacao"); 
string retorno = await oper.GetStringAsync(xuri); 
JObject jobject = JObject.Parse(retorno);  
var sidoperacao = jobject["value"][0]["IdOperacao"].ToString();

That is: in sidoperacao is contained the value "4234340".

    
10.10.2015 / 21:31