我有以下JSON文本.如何可以解析它来获得pageName,pagePic,post_id,等?
{
"pageInfo": {
"pageName": "abc",
"pagePic": "http://example.com/content.jpg"
},
"posts": [
{
"post_id": "123456789012_123456789012",
"actor_id": "1234567890",
"picOfPersonWhoPosted": "http://example.com/photo.jpg",
"nameOfPersonWhoPosted": "Jane Doe",
"message": "Sounds cool. Can't wait to see it!",
"likesCount": "2",
"comments": [],
"timeOfPost": "1234567890"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我想以JSON对象的形式将消息发送到服务器并解析来自服务器的JSON响应.
JSON对象的示例
{
"post": {
"username": "John Doe",
"message": "test message",
"image": "image url",
"time": "current time"
}
}
Run Code Online (Sandbox Code Playgroud)
我试图通过逐个属性来手动解析JSON.我可以使用任何库/实用程序来简化此过程吗?
我有以下json文件.我想知道在哪里将json文件放在我的项目中以及如何阅读和存储它.
{
"aakash": [
[ 0.070020,0.400684],
[ 0.134198,0.515837],
[ 0.393489,0.731809],
[ 0.281616,0.739490]
],
"anuj": [
[ 1287.836667,-22.104523],
[ -22.104523,308.689613],
[ 775.712801,-13.047385],
[ -13.047385,200.067743]
]
}
Run Code Online (Sandbox Code Playgroud) 我正在制作一个不需要用户帐户/登录的应用程序,并允许用户购买订阅.我想使用Google Play Developer API来验证用户是否有购买/有效订阅.从所有文档中,我收集了以下步骤.
它们是否正确,您能否回答其中的两个问题?
此外,我有一个Web服务,虽然我对Web服务或Web服务编程一无所知......我只知道它可能需要在这里使用.
编辑:这些步骤不正确.请参阅下面的答案,了解正确的步骤.但请注意,这仅适用于使用服务帐户(因为我不想要求用户必须明确允许API访问)
我试图通过使用用户名和密码解析登录URL来获取JSON数据.我试过使用下面的代码,但我无法得到任何答复.请帮我.
我正在使用HTTP Process和API level 23.
我需要解析我的URL并获得以下响应
{
"response":{
"Team":"A",
"Name":"Sonu",
"Class":"First",
},
"Result":"Good",
}
Run Code Online (Sandbox Code Playgroud)
在我的代码下面:
public class LoginActivity extends Activity {
JSONParser jsonparser = new JSONParser();
TextView tv;
String ab;
JSONObject jobj = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
new retrievedata().execute();
}
class retrievedata extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
jobj = jsonparser.makeHttpRequest("http://myurlhere.com");
// check your log for json response
Log.d("Login attempt", jobj.toString());
try {
ab = jobj.getString("title"); …Run Code Online (Sandbox Code Playgroud) 如何显示格式类似的JSON响应字符串json.parser.online.fr?
例如:如何在textview中显示以下代码?
{
"age":100,
"name":"mkyong.com",
"messages":["msg 1","msg 2","msg 3"]
}
Run Code Online (Sandbox Code Playgroud)
PS:最好是彩色格式.
简而言之 ..
1.如何格式化和显示JSON字符串?
2.如何格式化和显示Java代码?
我的资产文件夹中有一个JSON文件.该文件有一个带有数组的对象.该阵列有150多个对象,每个对象有三个字符串.
对于这150多个对象中的每一个,我想提取每个字符串并创建一个java模型对象,并传递三个字符串.我在android JSON解析中找到的所有教程都是从我不想做的url中获取JSON.
这有可能加载微调器中所有国家的列表,然后在选择特定国家时,其所有城市都出现在另一个微调器中,选择城市后,我们使用google在android中获取该城市的区域或城镇列表-api或类似国家/地区选择器的内容?目前,我正在使用它来获取国家列表。但是如何获得各自的城镇?
ArrayList<String> list=new ArrayList<String>();
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale obj = new Locale("", countryCode);
list.add(obj.getDisplayCountry());
}
Run Code Online (Sandbox Code Playgroud) 在收到通知时,我收到了下面提到的一些数据
Bundle[{google.sent_time=1233212221545, msg={"message":"You received a chat message","type":"Match Maker","request_id":"501"}, chat={"owner":0,"request_id":"501"}, from=148566781839, google.message_id=0:148354545211779676%c3fc9c6ff9fd7ecd, android.support.content.wakelockid=3, collapse_key=do_not_collapse}]
Run Code Online (Sandbox Code Playgroud)
从此我想要检索
messageRequest_idOwnertype我试图像这样检索
String mes1 = extras.getString("chat");
Run Code Online (Sandbox Code Playgroud)
我得到了这些价值观
{"owner":0,"request_id":"501"}
Run Code Online (Sandbox Code Playgroud)
示例:从上面我想获取所有者和请求ID如何检索这些值.
这是我的代码:
public class GCMIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private static final String TAG = "GcmIntentService";
UserLocalStore userLocalStore;
private NotificationManager mNotificationManager;
public GCMIntentService() {
super("GcmIntentService");
}
Intent notificationIntent;
String type,token,requestid,notify_message;
Context context;
@Override
protected void onHandleIntent(Intent intent) {
userLocalStore = new UserLocalStore(this);
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = …Run Code Online (Sandbox Code Playgroud) 我正在研究Retrofit,但我坚持一件事:如何在响应体上获得原始JSON.
public interface ViewMenuItems {
@GET
Call<ResponseBody> listRepos(@Url String url);
}
ViewMenuItems viewMenuItems = ApiClient.getClient().create(ViewMenuItems.class);
Call<ResponseBody> responseBodyCall = viewMenuItems.listRepos(Webservices.MERCHANT + merchantId + Webservices.MENU_ITEMS_LASTMODIFIED);
responseBodyCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.d("MenuItems", "Response :: " + response.body().toString());
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.d("MenuItems", "Exception :: " + t.toString());
}
});
Run Code Online (Sandbox Code Playgroud)
但是在"MenuItems"日志中,我没有得到JSON响应,它就是这样的
MenuItems: Response :: retrofit2.Response@e292dd4
Run Code Online (Sandbox Code Playgroud)
请通过我的帖子,并建议我一些解决方案.
android ×9
json ×7
google-api ×2
java ×2
parsing ×2
android-json ×1
google-maps ×1
google-play ×1
retrofit2 ×1
service ×1
subscription ×1
textview ×1