I implemented a webservice in asp.net which should return fortune cookie text in JSON format. The service is working and i´m able to consume the output of the webservice. However, the output is not as expected...
Websevice JSON output:
{"d": "{\"CookieText\":\"All you have to know is - what the hell is d ???\"}"}
As you might guess, i´m looking for the value of "CookieText" - but i don´t know how to get that. I´m able to get the following output:
{"CookieText":"All you have to know is - what the hell is d ???."}
with the code (where result = Websevice JSON output):
jsonObject = new JSONObject(result);
result_intern = jsonObject.getString("d");
But what i´m really looking for is just the value of CookieText. I tried the following lines with no success (result_intern is empty).
jsonObject = new JSONObject(result);
result_intern = jsonObject.getJSONObject("d").getString("CookieText");
I have two questions.
1) Why in the world is the output of the webservice packed into the variable (whatever?!) d ? Please enlighten me, what is the purpose of d? Is it something like 42? I really like to understand it before i send 1000s of hate mails to the developers. I did not tell anyone to put it into d... There is no d in the serialized class:
public class CFortuneCookieText
{
private string m_CookieText = "";
public string CookieText
{
get { return m_CookieText; }
set { m_CookieText = value; }
}
}
Webservice method:
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string GetFortuneCookieSayingsJSON()
{
CFortuneCookieText tmpObj = new CFortuneCookieText();
tmpObj.CookieText = "All you have to know is - what the hell is d ???";
return JsonConvert.SerializeObject(tmpObj, Formatting.None);
}
2) How do i get just the value of CookieText with the uage of JSONObject.getString?
Thanks in advance