Explore My Other Channel for More Cool and Valuable Insights
π Youtube Learn Tech Tipsπ Tiktok
π Facebook:You should use 2 function:
- One is convertStringToObjectsJSon
- Another is IEmumerable to cast type
View below code:
// insert System.Web.Script.Serialization namespace
using System.Web.Script.Serialization;
public static object convertStringToObjectsJson(string str)
{
try
{
// string str = "{ 'context_name': { 'lower_bound': 'value', 'pper_bound':
'value', 'values': [ 'value1', 'valueN' ] } }";
JavaScriptSerializer j = new JavaScriptSerializer();
object json = j.Deserialize(str, typeof(object));
if (json == null)
return null;
return json;
}
catch
{
return null;
}
}
string[] arString = new string[] { };
string sResult = getResponeseString("username", "password");
jsonResult = clsJson.convertStringToObjectsJson(sResult);
// convert json to array String[]
arString =
((IEnumerable)jsonResult).Cast<object>().Select(x => x.ToString()).ToArray();
getResponeseString(username, password)
getResponseseString is use httpwebresquest with GET method. You can see here
If you wanna download my full source code, you can download from here
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about
"Converting JSON to String Array in C#": A Step-by-Step Guide ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips, all things Tech Tips for web development
- I am Zidane, See you next time soon ✋✋✋✋