上传我自己的JSON文件ANDROID

时间:2015-08-15 17:38:35

标签: android json

如果我上传文件" radioData.json"到我的服务器www.mydomain.com/json/radioData.json。那么我可以使用我在这里的代码调用它,只需将URL转换为前一个代码吗?我问的原因是每当我做教程并从json数据中的API中提取它时,它永远不会有.json链接,所以这让我想知道我是否还必须做其他事情

谢谢!

这是我指的代码!

package com.dredaydesigns.radiostationfinder;

import android.R;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;


public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks {
String longitude;
    String latitude;
    String HTTPRadioURL = "https://transition.fcc.gov/fcc-bin/fmq?state=&call=&city=&arn=&serv=FC&vac=3&freq=0.0&fre2=107.9&facid=&asrn=&class=&dkt=&list=0&dist=100&dlat2="
            + latitude + "&mlat2=&slat2=&NS=N&dlon2="
            + longitude +"&mlon2=&slon2=&EW=W&size=9";

    public static final String TAG = MainActivity.class.getSimpleName();
    private RadioData mRadioData;

    private GoogleApiClient mGoogleApiClient;
    private Location mLastLocation;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_content);

       // latitude = (TextView) findViewById(R.id.latitudeLabel);
       // longitude = (TextView) findViewById(R.id.longitudeLabel);

        double latitude = 32;
        double longitude = -96;
        final RadioData[] mRadioData = new RadioData[1];
       String radioFinderURL = "http://data.fcc.gov/lpfmapi/rest/v1/lat/" + latitude + "/long/" + longitude + "?format=json&secondchannel=true";
       //String HTTPRadioURL = "https://transition.fcc.gov/fcc-bin/fmq?state=&call=&city=&arn=&serv=FC&vac=3&freq=0.0&fre2=107.9&facid=&asrn=&class=&dkt=&list=0&dist=100&dlat2="
          //      + latitude + "&mlat2=&slat2=&NS=N&dlon2="
           //     + longitude +"&mlon2=&slon2=&EW=W&size=9";


        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(radioFinderURL)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(Response response) throws IOException {
                try {
                    String jsonData = response.body().string();
                    Log.v(TAG,jsonData);
                    if (response.isSuccessful()) {
                        mRadioData[0] = getCurrentDetails(jsonData);

                    }

                } catch (IOException e) {
                    Log.e(TAG, "Exception Caught: ", e);
                }
                catch(JSONException e){
                    Log.e(TAG, "Exception Caught:", e);
                }
            }
        });

    }

    private RadioData getCurrentDetails(String jsonData) throws JSONException {
        JSONObject radioData = new JSONObject(jsonData);
        String callSign;
        JSONArray jsonArray = radioData.getJSONArray("interferingAnalysis");
        for(int i =0; i<jsonArray.length(); i++){
            callSign = radioData.getJSONObject(i+"")
                    .getJSONArray("interferingChannels").getJSONObject(i).getString("callsign");
        Log.i(TAG, "From JSON: " + callSign);

        JSONObject currently = radioData.getJSONObject("frequency");
        RadioData radioFinder = new RadioData();

        }
            return new RadioData();


    }

    protected synchronized void buildGoogleApiClient() {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener) this)
                .addApi(LocationServices.API)
                .build();


    }


    @Override
    public void onConnected(Bundle bundle) {
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (mLastLocation != null) {
           // latitudeLabel.setText(String.valueOf(mLastLocation.getLatitude()));
            //longitudeLabel.setText(String.valueOf(mLastLocation.getLongitude()));
        }
    }


    @Override
    public void onConnectionSuspended(int i) {

    }


}

好的,我已经更新了文件并运行它,它似乎正在工作,因为它在我使用此代码时抓取了一些JSON数据。

 String radioFinderURL = "http://dredaycreative.com/json/radioData.json";

        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(radioFinderURL)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(Response response) throws IOException {
                try {
                    String jsonData = response.body().string();
                    Log.v(TAG,jsonData);
                    if (response.isSuccessful()) {
                        mRadioData[0] = getCurrentDetails(jsonData);

                    }

                } catch (IOException e) {
                    Log.e(TAG, "Exception Caught: ", e);
                }
                catch(JSONException e){
                    Log.e(TAG, "Exception Caught:", e);
                }
            }
        });

    }

    private RadioData getCurrentDetails(String jsonData) throws JSONException {
        JSONObject radioData = new JSONObject(jsonData);
        String callSign;
        JSONArray jsonArray = radioData.getJSONArray("array");
        for(int i =0; i<jsonArray.length(); i++){
            callSign = radioData.getJSONObject(i+"")
                    .getJSONArray("array").getJSONObject(i).getString("FIELD1");
        Log.i(TAG, "From JSON: " + callSign);

        JSONObject currently = radioData.getJSONObject("frequency");
        RadioData radioFinder = new RadioData();

        }
            return new RadioData();

我在logcat中得到了以下内容

08-15 15:48:40.868    7157-7157/com.dredaydesigns.radiostationfinder E/Zygote﹕ MountEmulatedStorage()
08-15 15:48:40.868    7157-7157/com.dredaydesigns.radiostationfinder E/Zygote﹕ v2
08-15 15:48:40.868    7157-7157/com.dredaydesigns.radiostationfinder I/libpersona﹕ KNOX_SDCARD checking this for 10230
08-15 15:48:40.868    7157-7157/com.dredaydesigns.radiostationfinder I/libpersona﹕ KNOX_SDCARD not a persona
08-15 15:48:40.908    7157-7157/com.dredaydesigns.radiostationfinder I/SELinux﹕ Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-G900T_5.0 ver=27
08-15 15:48:40.908    7157-7157/com.dredaydesigns.radiostationfinder I/SELinux﹕ Function: selinux_compare_spd_ram , priority [1] , priority version is VE=SEPF_SM-G900T_5.0_0027
08-15 15:48:40.908    7157-7157/com.dredaydesigns.radiostationfinder E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
08-15 15:48:40.908    7157-7157/com.dredaydesigns.radiostationfinder I/art﹕ Late-enabling -Xcheck:jni
08-15 15:48:40.938    7157-7157/com.dredaydesigns.radiostationfinder D/TimaKeyStoreProvider﹕ TimaSignature is unavailable
08-15 15:48:40.938    7157-7157/com.dredaydesigns.radiostationfinder D/ActivityThread﹕ Added TimaKeyStore provider
08-15 15:48:41.188    7157-7157/com.dredaydesigns.radiostationfinder D/ResourcesManager﹕ creating new AssetManager and set to /data/app/com.dredaydesigns.radiostationfinder-2/base.apk
08-15 15:48:41.598    7157-7157/com.dredaydesigns.radiostationfinder D/AbsListView﹕ Get MotionRecognitionManager
08-15 15:48:41.678    7157-7157/com.dredaydesigns.radiostationfinder D/Activity﹕ performCreate Call secproduct feature valuefalse
08-15 15:48:41.678    7157-7157/com.dredaydesigns.radiostationfinder D/Activity﹕ performCreate Call debug elastic valuetrue
08-15 15:48:41.768    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 61.842ms
08-15 15:48:41.848    7157-7226/com.dredaydesigns.radiostationfinder D/OpenGLRenderer﹕ Render dirty regions requested: true
08-15 15:48:41.958    7157-7226/com.dredaydesigns.radiostationfinder I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.25.01.03
    Build Date: 10/28/14 Tue
    Local Branch: LA.BF.1.1_RB1_20141028_021_patches2
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
08-15 15:48:41.958    7157-7226/com.dredaydesigns.radiostationfinder I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-15 15:48:42.048    7157-7226/com.dredaydesigns.radiostationfinder I/OpenGLRenderer﹕ HWUI protection enabled for context ,  &this =0xaf822088 ,&mEglDisplay = 1 , &mEglConfig = 8
08-15 15:48:42.048    7157-7226/com.dredaydesigns.radiostationfinder D/OpenGLRenderer﹕ Enabling debug mode 0
08-15 15:48:42.108    7157-7157/com.dredaydesigns.radiostationfinder I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@18fd5d03 time:80192569
08-15 15:48:53.438    7157-7157/com.dredaydesigns.radiostationfinder I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@18fd5d03 time:80203894
08-15 15:49:12.178    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 124.865ms
08-15 15:50:00.838    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 16.649ms
08-15 15:50:00.878    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 26.681ms
08-15 15:50:01.208    7157-7201/com.dredaydesigns.radiostationfinder V/MainActivity﹕ [
    {
    "FIELD1":"WGCU-FM     ",
    "FIELD2":"90.1  MHz ",
    "FIELD3":"FS ",
    "FIELD4":211,
    "FIELD5":"ND  ",
    "FIELD6":"-                   ",
    "FIELD7":"C1 ",
    "FIELD8":"-  ",
    "FIELD9":"LIC    ",
    "FIELD10":"FORT MYERS               ",
    "FIELD11":"FL ",
    "FIELD12":"US ",
    "FIELD13":"BXLH   -20120420ABN ",
    "FIELD14":"30.    kW ",
    "FIELD15":"30.    kW ",
    "FIELD16":221,
    "FIELD17":221,
    "FIELD18":69042,
    "FIELD19":"N ",
    "FIELD20":26,
    "FIELD21":48,
    "FIELD22":54,
    "FIELD23":"W ",
    "FIELD24":81,
    "FIELD25":45,
    "FIELD26":43,
    "FIELD27":"BOARD OF TRUSTEES, FLORIDA GULF COAST UNIVERSITY                            ",
    "FIELD28":"   0.00 km ",
    "FIELD29":"   0.00 mi ",
    "FIELD30":"  0.00 deg ",
    "FIELD31":"229.   m",
    "FIELD32":"229.0  m",
    "FIELD33":"-         ",
    "FIELD34":"-       ",
    "FIELD35":"1020483",
    "FIELD36":"220.   m",
    "FIELD37":1496547
    },
    {
    "FIELD1":"KBBO-FM     ",
    "FIELD2":"92.1  MHz ",
    "FIELD3":"FM ",
    "FIELD4":221,
    "FIELD5":"ND  ",
    "FIELD6":"-                   ",
    "FIELD7":"C2 ",
    "FIELD8":"-  ",
    "FIELD9":"LIC    ",
    "FIELD10":"HOUSTON                  ",
    "FIELD11":"AK ",
    "FIELD12":"US ",
    "FIELD13":"BLH    -20030916AAH ",
    "FIELD14":"10.    kW ",
    "FIELD15":"10.    kW ",
    "FIELD16":270,
    "FIELD17":270,
    "FIELD18":68694,
    "FIELD19":"N ",
    "FIELD20":61,
    "FIELD21":20,
    "FIELD22":11,
    "FIELD23":"W ",
    "FIELD24":149,
    "FIELD25":30,
    "FIELD26":48,
    "FIELD27":"OMG FCC LICENSES LLC                                                        ",
    "FIELD28":"   0.00 km ",
    "FIELD29":"   0.00 mi ",
    "FIELD30":"  0.00 deg ",
    "FIELD31":"598.   m",
    "FIELD32":"598.0  m",
    "FIELD33":"-         ",
    "FIELD34":"-       ",
    "FIELD35":"1204036",
    "FIELD36":"20.    m",
    "FIELD37":680555
    },
    {
    "FIELD1":"WKUL        ",
    "FIELD2":"92.1  MHz ",
    "FIELD3":"FM ",
    "FIELD4":221,
    "FIELD5":"ND  ",
    "FIELD6":"-                   ",
    "FIELD7":"A  ",
    "FIELD8":"-  ",
    "FIELD9":"LIC    ",
    "FIELD10":"CULLMAN                  ",
    "FIELD11":"AL ",
    "FIELD12":"US ",
    "FIELD13":"BLH    -19951024KD  ",
    "FIELD14":"6.     kW ",
    "FIELD15":"6.     kW ",
    "FIELD16":100,
    "FIELD17":100,
    "FIELD18":31933,
    "FIELD19":"N ",
    "FIELD20":34,
    "FIELD21":11,
    "FIELD22":41,
    "FIELD23":"W ",
    "FIELD24":86,
    "FIELD25":43,
    "FIELD26":52,
    "FIELD27":"JONATHAN CHRISTIAN CORP.                                                    ",
    "FIELD28":"   0.00 km ",
    "FIELD29":"   0.00 mi ",
    "FIELD30":"  0.00 deg ",
    "FIELD31":"342.   m",
    "FIELD32":"342.0  m",
    "FIELD33":"-         ",
    "FIELD34":"-       ",
    "FIELD35":"-       ",
    "FIELD36":"92.    m",
    "FIELD37":215650
    },
    {
    "FIELD1":"WJJN        ",
    "FIELD2":"92.1  MHz ",
    "FIELD3":"FM ",
    "FIELD4":221,
    "FIELD5":"ND  ",
    "FIELD6":"-                   ",
    "FIELD7":"A  ",
    "FIELD8":"-  ",
    "FIELD9":"LIC    ",
    "FIELD10":"COLUMBIA                 ",
    "FIELD11":"AL ",
    "FIELD12":"US ",
    "FIELD13":"BLH    -19951213KB  ",
    "FIELD14":"2.55   kW ",
    "FIELD15":"2.55   kW ",
    "FIELD16":152,
    "FIELD17":152,
    "FIELD18":30280,
    "FIELD19":"N ",
    "FIELD20":31,
    "FIELD21":10,
    "FIELD22":25,
    "FIELD23":"W ",
    "FIELD24":85,
    "FIELD25":12,
    "FIELD26":49,
    "FIELD27":"WILSON BROADCASTING CO., INC.                                               ",
    "FIELD28":"   0.00 km ",
    "FIELD29":"   0.00 mi ",
    "FIELD30":"  0.00 deg ",
    "FIELD31":"216.   m",
    "FIELD32":"216.0  m",
    "FIELD33":"-         ",
    "FIELD34":"-       ",
    "FIELD35":"-       ",
    "FIELD36":"146.   m",
    "FIELD37":217857


       },
        {
        "FIELD1":
    08-15 15:50:02.898    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 18.539ms
    08-15 15:50:02.898    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 7.261ms
    08-15 15:50:05.398    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 16.810ms
    08-15 15:50:06.408    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 26.965ms
    08-15 15:50:06.448    7157-7201/com.dredaydesigns.radiostationfinder I/art﹕ WaitForGcToComplete blocked for 18.019ms for cause Alloc
    08-15 15:50:06.498    7157-7201/com.dredaydesigns.radiostationfinder I/art﹕ WaitForGcToComplete blocked for 7.471ms for cause Alloc
    08-15 15:50:06.768    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 5.497ms
    08-15 15:50:06.958    7157-7166/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 72.266ms
    08-15 15:50:06.958    7157-7201/com.dredaydesigns.radiostationfinder I/art﹕ WaitForGcToComplete blocked for 159.391ms for cause Alloc
    08-15 15:50:06.988    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspend

ing all threads took: 22.886ms
08-15 15:50:07.148    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 14.793ms
08-15 15:50:07.248    7157-7178/com.dredaydesigns.radiostationfinder W/art﹕ Suspending all threads took: 42.333ms
08-15 15:50:07.258    7157-7201/com.dredaydesigns.radiostationfinder E/MainActivity﹕ Exception Caught:
    org.json.JSONException: Value [{"FIELD1":"WGCU-FM     ","FIELD2":"90.1  MHz ","FIELD3":"FS ","FIELD4":211,"FIELD5":"ND  ","FIELD6":"-                   ","FIELD7":"C1 ","FIELD8":"-  ","FIELD9":"LIC    ","FIELD10":"FORT MYERS               ","FIELD11":"FL ","FIELD12":"US ","FIELD13":"BXLH   -20120420ABN ","FIELD14":"30.    kW ","FIELD15":"30.    kW ","FIELD16":221,"FIELD17":221,"FIELD18":69042,"FIELD19":"N ","FIELD20":26,"FIELD21":48,"FIELD22":54,"FIELD23":"W ","FIELD24":81,"FIELD25":45,"FIELD26":43,"FIELD27":"BOARD OF TRUSTEES, FLORIDA GULF COAST UNIVERSITY                            ","FIELD28":"   0.00 km ","FIELD29":"   0.00 mi ","FIELD30":"  0.00 deg ","FIELD31":"229.   m","FIELD32":"229.0  m","FIELD33":"-         ","FIELD34":"-       ","FIELD35":"1020483","FIELD36":"220.   m","FIELD37":1496547},{"FIELD1":"KBBO-FM     ","FIELD2":"92.1  MHz ","FIELD3":"FM ","FIELD4":221,"FIELD5":"ND  ","FIELD6":"-                   ","FIELD7":"C2 ","FIELD8":"-  ","FIELD9":"LIC    ","FIELD10":"HOUSTON                  ","FIELD11":"AK ","FIELD12":"US ","FIELD13":"BLH    -20030916AAH ","FIELD14":"10.    kW ","FIELD15":"10.    kW ","FIELD16":270,"FIELD17":270,"FIELD18":68694,"FIELD19":"N ","FIELD20":61,"FIELD21":20,"FIELD22":11,"FIELD23":"W ","FIELD24":149,"FIELD25":30,"FIELD26":48,"FIELD27":"OMG FCC LICENSES LLC                                                        ","FIELD28":"   0.00 km ","FIELD29":"   0.00 mi ","FIELD30":"  0.00 deg ","FIELD31":"598.   m","FIELD32":"598.0  m","FIELD33":"-         ","FIELD34":"-       ","FIELD35":"1204036","FIELD36":"20.    m","FIELD37":680555},{"FIELD1":"WKUL        ","FIELD2":"92.1  MHz ","FIELD3":"FM ","FIELD4":221,"FIELD5":"ND  ","FIELD6":"-                   ","FIELD7":"A  ","FIELD8":"-  ","FIELD9":"LIC    ","FIELD10":"CULLMAN                  ","FIELD11":"AL ","FIELD12":"US ","FIELD13":"BLH    -19951024KD  ","FIELD14":"6.     kW ","FIELD15":"6.     kW ","FIELD16":100,"FIELD17":100,"FIELD18":31933,"FIELD19":"N ","FIELD20":34,"FIELD21":11,"FIELD22":41,"FIELD23":"W ","FIELD24":86,"FIELD25":43,"FIELD26":52,"FIELD27":"JONATHAN CHRISTIAN CORP.                                                    ","FIELD28":"   0.00 km ","FIELD29":"   0.00 mi ","FIELD30":"  0.00 deg ","FIELD31":"342.   m","FIELD32":"342.0  m","FIELD33":"-         ","FIELD34":"-       ","FIELD35":"-       ","FIELD36":"92.    m","FIELD37":215650},{"FIELD1":"WJJN        ","FIELD2":"92.1  MHz ","FIELD3":"FM ","FIELD4":221,"FIELD5":"ND  ","FIELD6":"-                   ","FIELD7":"A  ","FIELD8":"-  ","FIELD9":"LIC    ","FIELD10":"COLUMBIA                 ","FIELD11":"AL ","FIELD12":"US ","FIELD13":"BLH    -19951213KB  ","FIELD14":"2.55   kW ","FIELD15":"2.55   kW ","FIELD16":152,"FIELD17":152,"FIELD18":30280,"FIELD19":"N ","FIELD20":31,"FIELD21":10,"FIELD22":25,"FIELD23":"W ","FIELD24":85,"FIELD25":12,"FIELD26":49,"FIELD27":"WILSON BROADCASTING CO., INC.                                               ","FIELD28":"   0.00 km ","FIELD29":"   0.00 mi ","FIELD30":"  0.00 deg ","FIELD31":"216.   m","FIELD32":"216.0  m","FIELD33":"-         ","FIELD34":"-       ","FIELD35":"-       ","FIELD36":"146.   m","FIELD37":217857},{"FIELD1":"WERH-FM     ","FIELD2":"92.1  MHz ","FIELD3":"FM ","FIELD4":221,"FIELD5":"ND  ","FIELD6":"-                   ","FIELD7":"A  ","FIELD8":"-  ","FIELD9":"LIC    ","FIELD10":"HAMILTON                 ","FIELD11":"AL ","FIELD12":"US ","FIELD13":"BLH    -3981        ","FIELD14":"3.     kW ","FIELD15":"3.     kW ","FIELD16":37,"FIELD17":37,"FIELD18":33473,"FIELD19":"N ","FIELD20":34,"FIELD21":7,"FIELD22":1,"FIELD23":"W ","FIELD24":87,"FIELD25":59,"FIELD26":29,"FIELD27":"KATE F. FITE                                                                ","FIELD28":"   0.00 km ","FIELD29":"   0.00 mi ","FIELD30":"  0.00 deg ","FIELD31":"202.   m","FIELD32":"202.0  m","FIELD33":"-         ","FIELD34":"-       ","FIELD35":"-       ","FIELD36":"87.    m","FIELD37":300205},{"FIELD1":"WZEW        ","FIELD2":"92.1  MHz ","FIELD3":"FM ","FIELD4":221,"FIELD5":"ND  ","FIELD6":"-

我不确定异常是什么告诉了我,然后现在我很好奇我将如何根据FCC之前的经度和纬度来查询这些结果

0 个答案:

没有答案