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

Asked

Viewed 436 times

-2

After accessing the WCF, I get the following answer:

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

How do I extract the Value of IdOperacao for a string?

  • 3

    Can you tell us clearly what your doubt is?

  • Hello, Luiz, welcome to [en.so]. Please try to be much more specific when asking a question, so avoid this history of negative vote, question closing, reopening... and direct part to solve the problem. It seems that with what you presented it is already possible to answer... maybe there is already some question/answer ready on the site, the C# people will tell. Good luck!

1 answer

2

Here is the Solution:

The answer to the WCF call:

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

Below the call code is the conversion of the field "Idoperacao" in 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 the value "4234340".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.