这段代码给出了带有json标签的空json字符串,请为此提供帮助 [英] This code is giving null json string with json tags please help for this
本文介绍了这段代码给出了带有json标签的空json字符串,请为此提供帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string json = new WebClient().DownloadString(" http://[doaminName]/rpsconline/rest/kioskWebService/getApplicationStatus?dob=" + dob + "&token_transaction_no=" + mobileno);
string[] s1 = new string[] { "application_id", "candidateName", "dob", "fatherName", "mobileNo", "responseError", "responseStatus", "[", "{", "\"", ":", ".", ",", "}", "]" };
string[] strSplitArr = json.Split(s1, StringSplitOptions.RemoveEmptyEntries);
我在json变量中遇到问题,它给出了空值。
I am getting problem in json variable, it is giving null values.
推荐答案
你的尝试解决方案并解析答案(这是json)作为字符串你自己是一个坏的...
声明具有答案结构的类:
Your solution to try and parse the answer (which is json) as string by yourself is a bad one...
Declare class with the structure of the answer:
public class Result
{
public string ApplicationID;
public string CandidateName;
// so on
}
Then use Json.NET[^] to parse it for you...
Result res = JsonConvert.DeserializeObject<Result[]>(json);
您应该使用数组类型,因为JSON正在返回一个数组。
You should use array type as JSON is returning an array.
Result res = JsonConvert.DeserializeObject<Result[]>(json);
另外你应该正确地遵循错误信息,你可能会提供错误的查询字符串值和有效密钥。
那是:Key:
Another thing you should follow the error message properly it may be case of you are provide wrong query string value with valid key.
That's is : Key :
token_transaction_no
但值是:MobileNo
but Value is : MobileNo
这篇关于这段代码给出了带有json标签的空json字符串,请为此提供帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文