Android App Json
I writing android app and faced problem. I have API and write it to file. Code of writing string url2 = 'http://new.murakami.ua/?mkapi=getProducts'; JsonValue json = await
Solution 1:
There are many, many different ways to read/write data in .NET. This is just one fairly simple approach
// assuming data is System.Json.JsonValue with your data// write data to file
File.WriteAllText(path, data.ToString());
// read back datastringrawdata= File.ReadAllText(path);
// parse it into a JsonValueJsonValuejson= JsonValue.Parse(rawdata);
Solution 2:
Man you are using Xamarin. But here some tips of how I solve it in Android native code.
- I saved the file in the Assets folder;
- them saved the fale with .json extension not .txt;
I accessed it using this code:
private static String loadJSONFromAsset(Context context, String fileName) { String json = null; try { InputStream is = context.getAssets().open("contactos/" + fileName + ".json"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new String(buffer); } catch (IOException ex) { ex.printStackTrace(); return null; } return json; }
After that I parse the JSON with no problem.
And it works perfectly, I hope it will help you.
Post a Comment for "Android App Json"