NEWEST UPDATE 印刷は "conditon"
package com.karanvir.again;
import android.os.AsyncTask;
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.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
EditText city;
Button go;
TextView resultofw;
String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
city=(EditText) findViewById(R.id.editText);
go=(Button) findViewById(R.id.button);
setSupportActionBar(toolbar);
DownloadTask task=new DownloadTask();
resultofw=(TextView) findViewById(R.id.textView);
task.execute("http://api.apixu.com/v1/current.json?key=76d62bf509e64633a4970055170706&q="+city.toString());
}
public class DownloadTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... urls) {
String result = "";
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(urls[0]);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();
while (data != -1) {
char current = (char) data;
result += current;
data = reader.read();
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//conver result into json object
try{
JSONObject jsonObject=new JSONObject(result);
//get current JSONObject from result JSONObject
JSONObject currentJSONObject = jsonObject.getJSONObject("current");
//Now get condition JSONObject from current JSONObject
JSONObject conditionJSONObject = currentJSONObject.getJSONObject("condition");
text = conditionJSONObject.getString("text");
//Now print condition JSONObject
Log.i("website content", "condition json object : " + text.toString());
JSONArray arr= new JSONArray(conditionJSONObject.toString());
} catch (Exception e){
}
}
}
public void click(View view){
resultofw.setText(text);
}
}
//conver result into json object
try{
JSONObject jsonObject=new JSONObject(result);
//get current JSONObject from result JSONObject
JSONObject currentJSONObject = jsonObject.getJSONObject("current");
//Now get condition JSONObject from current JSONObject
JSONObject conditionJSONObject = currentJSONObject.getJSONObject("condition");
//Now print condition JSONObject
Log.i("website content", "condition json object : " + conditionJSONObject.toString());
JSONArray arr= new JSONArray(conditionJSONObject.toString());
for(int i=0;i<arr.length();i++){
JSONObject jsonpart= arr.getJSONObject(i);
Log.i("Part",jsonpart.getString("text"));
}
「は」条件「後の印刷すべて何をしようとしているイムある」曇り」は、 "icon": "// cdn.apixu.com/weather/64x64/day/116.png"、 "code":1003}、 "wind_mph":15.0,"wind_kph ":24.1,"wind_degree":240、 wind_dir ":" WSW "、" pressure_mb ":1016.0、" pressure_in ":30.5、" precip_mm ":0.0、" precip_in ":0.0、" humidity ":71、" cloud ":50、" feelslike_c ":9.6、私のログには、Jを使用しています:このサイトからのデータを処理するためSONG:http://api.apixu.com/v1/current.json?key=76d62bf509e64633a4970055170706&q=Paris その私のlogcatに表示されない、を助けてください、はい、私が含まれているMY MENIFESTでのPermissionを使用しています
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.karanvir.again.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
06-07 01:42:19.594 20523-20523/com.karanvir.again E/Zygote: v2
06-07 01:42:19.594 20523-20523/com.karanvir.again I/libpersona: KNOX_SDCARD checking this for 10291
06-07 01:42:19.594 20523-20523/com.karanvir.again I/libpersona: KNOX_SDCARD not a persona
06-07 01:42:19.594 20523-20523/com.karanvir.again I/SELinux: Function: selinux_compare_spd_ram, index[1], SPD-policy is existed. and_ver=SEPF_SM-G870W_5.0 ver=38
06-07 01:42:19.594 20523-20523/com.karanvir.again W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0013
06-07 01:42:19.594 20523-20523/com.karanvir.again E/Zygote: accessInfo : 0
06-07 01:42:19.594 20523-20523/com.karanvir.again W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=com.karanvir.again
06-07 01:42:19.594 20523-20523/com.karanvir.again I/art: Late-enabling -Xcheck:jni
06-07 01:42:19.974 20523-20523/com.karanvir.again W/ResourcesManager: getTopLevelResources: /data/app/com.karanvir.again-2/base.apk/1.0 running in com.karanvir.again rsrc of package null
06-07 01:42:20.064 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.304 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.364 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.414 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.484 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.544 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.614 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.694 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.754 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.814 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.894 20523-20523/com.karanvir.again W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/com.karanvir.again-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
06-07 01:42:20.894 20523-20523/com.karanvir.again W/System: ClassLoader referenced unknown path: /data/app/com.karanvir.again-2/lib/arm
06-07 01:42:20.914 20523-20523/com.karanvir.again I/InstantRun: starting instant run server: is main process
06-07 01:42:20.994 20523-20523/com.karanvir.again W/ResourcesManager: getTopLevelResources: /data/app/com.karanvir.again-2/base.apk/1.0 running in com.karanvir.again rsrc of package null
06-07 01:42:20.994 20523-20523/com.karanvir.again W/ResourcesManager: getTopLevelResources: /data/app/com.karanvir.again-2/base.apk/1.0 running in com.karanvir.again rsrc of package null
06-07 01:42:21.114 20523-20523/com.karanvir.again W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-07 01:42:21.424 20523-20780/com.karanvir.again I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
06-07 01:42:21.424 20523-20780/com.karanvir.again I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
06-07 01:42:21.464 20523-20787/com.karanvir.again I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ia10634f51b)
OpenGL ES Shader Compiler Version: E031.29.00.00
Build Date: 01/28/16 Thu
Local Branch: ss
Remote Branch:
Local Patches:
Reconstruct Branch:
06-07 01:42:21.474 20523-20787/com.karanvir.again I/OpenGLRenderer: Initialized EGL, version 1.4
06-07 01:42:21.544 20523-20523/com.karanvir.again W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
06-07 01:42:21.574 20523-20523/com.karanvir.again I/Timeline: Timeline: Activity_idle id: [email protected] time:300881669
package com.karanvir.again;
import android.os.AsyncTask;
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.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DownloadTask task=new DownloadTask();
task.execute("http://api.apixu.com/v1/current.json?key=76d62bf509e64633a4970055170706&q=Paris");
}
public class DownloadTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... urls) {
String result = "";
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(urls[0]);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();
while (data != -1) {
char current = (char) data;
result += current;
data = reader.read();
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//conver result into json object
try{
JSONObject jsonObject=new JSONObject(result);
String xx=jsonObject.getString("condition");
Log.i("website content", xx);
} catch (Exception e){
}
}
}
}
下回る(Log.d( "ウェブサイトのコンテンツ"、jsonObject.getStringを試すような "テキスト" の値を取得するために
conditionJSONObject
にgetString
メソッドを呼び出します"条件")。toString()); –明らかにあなたはいくつかのjsonの基礎を学ぶべきです...状態のプロパティはルートレベルにありません – Selvin