I created an array and I want to send it to a C# application. I want to be able to use it as a C# string array so I can create a for loop where I can run some tasks.
Node.js (Express.js)
router.get('/arr', function(req,res,next) { var arr = ["orange", "plum", "strawberry", "lemon", "tangerine"]; res.send(arr); });
C# code.
public string Arr() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.0.2.2/arr"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader stream = new StreamReader(response.GetResponseStream()); string final_response = stream.ReadToEnd(); stream.Dispose(); return final_response; }
C# application's editor (This is an editor where I can do very limited stuff, so there's no way to import 3rd party packages but you can do basic stuff like http get/post, etc)
string Answer = Lib.Arr();
How can I create Answer
as a string array? I tried creating Answer
as string[] Answer
but it says string can't get converted into string[], where am I wrong?
I'm new to C#.
final_response
is a string with the json, it isn't an array yet. Casting won't work. You actually need to parse it. If you had access to libraries, you could use Newtonsoft: newtonsoft.com/json . Depending on your editor, maybe you have access to DataContractJsonSerializer. Here is an example how to use it:stackoverflow.com/questions/8204320/…