- Home /
C# - Read JSON
I need to read a JSON that is printed in a php file hosted online.
I'm doing this:
using(WebClient wb = new WebClient()){
var data = new NameValueCollection();
data["email"] = emailUser;
data["idFB"] = id;
var response = wb.UploadValues(url.ToString(), "POST", data);
yield return response;
}
How can I read a json after doing this in C#?
Answer by Landern · Jul 23, 2014 at 01:03 PM
Include(or develop your own) a Json library for parsing the Json for consumption by your program. The Unify Community has posted SimpleJson for free for you to use.
You can find SimpleJson here. There are also instructions for inclusion in your project on that same wiki entry.
Edit: You may want to use Unity's WWWForm(to post) class instead of .net's WebRequest
Edit 2: Something like:
WWWForm form = new WWWForm();
form.AddField("email", emailUser);
form.AddField("idFB", id);
WWW webRequest = new WWW(url.ToString(), form);
yield webRequest;
You will find your json in webRequest.text, parse that.
Yes, I know that library, but, my question is how to read the json from the php file? Not parsing it. Thanks.
You need to output it, as a response to the web request, you can use echo in php if you want, there are a bunch of ways to do it and it's really a php question and not a unity question.
I'm using echo to output. And sorry if I'm not understanding, but, after the echo and before the parse, how do I get the JSON in my C#? Is it with the response var? Thanks again !
Opps, sorry about that, i was on my mobile. Encoding.ASCII.GetString(response);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to send data form to server using json in unity 1 Answer
PHP Image to C# 2D Texture 2 Answers