Here is my code sending json
string input = "{\"DeviceID\":12345, \"DeviceType\":A, \"GameType\":SM, \"LevelDesc\":Testing Desc, \"User_ID\":111, \"Alwords\":12345}";
Hashtable headers = new Hashtable();
headers.Add("Content-Type", "application/json");
byte[] body = Encoding.UTF8.GetBytes(input);
WWW www = new WWW("http://wordnexus.info/WNWS/WNS/RequestNewGameDefault", body, headers);
But i am getting error
error CS0103: The name `Encoding’ does not exist in the current context
How to escape from this error
You see this when you use an identifier in your code (‘Encoding’ here) that the compiler does not know about. As you can read here, the Encoding class is part of the System.Text namespace (you can read about what a namespace is on Wikipedia if needed).
In order for the compiler to accept your program, you must either
- use the full name of the class, which is System.Text.Encoding (and therefore you would write System.Text.Encoding.UTF8.GetBytes(input))
- or add the “using System.Text;” directive at the beginning of your source file to tell the compiler that if he does not know about the “Encoding” class, it should also check whever there is a System.Text.Encoding class available.