android


Cannot resolve JSON on android


I'm having this problem with JSON and okhttp in android.
can anyone point me in the right direction? im new at this so any help would do.
This are my imports:
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONException;
import org.json.*;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.MediaType;
You're missing the declaration of the JSON reference:
public static final MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
From the sample code in the documentation:
public class PostExample {
public static final MediaType JSON
= MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}
Note that it's always a good idea to look at the documentation for the code you're using, in this case where you're calling RequestBody.create() you can look at the documentation for this method, where you can see that the first parameter is a MediaType reference:
public static RequestBody create(MediaType contentType,
String content)
Returns a new request body that transmits content. If contentType is non-null and lacks a charset,
this will use UTF-8.

Related Links

How to re-run loader whenever data changed DB by a service
Pass limit & offset to request - Facebook SDK for Android 3.0
SDK 3.0 reauthorizeForPublish() loses read permissions?
Copy resources efficiently with the command line into another project
ProgressDialog closing onClick
using location api in android [duplicate]
Android translationY on custom layout
Android - Spinner not spinning. Spinner freezed
NETWORK_PROVIDER not giving callback to onLocationChanged()
Calling the onCreateOptionsMenu() for the actionbarsherlock
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
java.lang.illegalStateException during performing Search using Android Search Configration
How to display paragraph <p> some paragraph </p> inside TextView without showing <p>?
Android UI ListView
crash load image from website [duplicate]
Google Play Market account for different applications

Categories

HOME
android
developer-tools
ng-idle
graphics
alsa
zip
jetty
data-visualization
jax-ws
mvc5
extjs4.2
qpython
spin
jsonpath
cumulocity
coin3d
modbus-tcp
internationalization
glyphicons
imessage
shortest-path
href
stackexchange
vex
r-grid
hard-drive
carriage-return
video-capture
xajax
apiary.io
cd
metaprogramming
urlsession
clang++
opencmis
rxtx
vcloud-director-rest-api
slackware
angular2-testing
atlas
mapxtreme
parfor
qtplugin
flex4.6
windows-azure-queues
jclouds
freepbx
createprocess
nupic
database-relations
dynatree
avisynth
xenomai
forwarding
google-books
extjs-grid
.bash-profile
visual-sourcesafe-2005
rpart
aspectj-maven-plugin
phpldapadmin
dbaccess
angular-gettext
rmysql
android-framework
file-not-found
spring-3
sphinxql
code-duplication
modular
time.h
epiceditor
actiondispatch
pdfviewer
mkv
vfs
wcf-configuration
subgraph
fusefabric
apache-whirr
hibernateexception
denied
fsevents
creole
uipagecontrol
tmx
dot-emacs
opml
echo3
wordprocessingml
perl5.12
firefox-3
httpcookie
appliance

Resources

Encrypt Message