循环遍历数据对象并输出每个对象的对象文件名和消息

时间:2017-04-24 15:29:18

标签: javascript java arrays json loops

如何遍历每个数据对象的ajax请求并为每个文件提取文件名,消息?有人可以帮忙吗?

将List解析回客户端的服务器端控制器:

@RequestMapping(value = { "/fileUpload" }, method = RequestMethod.POST)
@ResponseBody
public List<FileUpload> uploadFile( @RequestParam("number") String number, @RequestParam("files[]") MultipartFile[] files, MultipartHttpServletRequest req, HttpServletResponse res)
{       
    WebUserSession session = (WebUserSession) req.getSession().getAttribute("webUserSession");
    String windowsUsername = session.getUsername();


    List<FileUpload> fileList = itsmService.uploadFile(files, windowsUsername, number);
    int countTrue = 0;
    int countFalse = 0;

    for (FileUpload loopFile : fileList) 
    {
        if (loopFile.getSuccess())
        {
            countTrue++;
        }
        else
        {
            countFalse++;
        }

    }



    return fileList;
}
}

ajax请求的一部分客户端数据对象:

success : function(data) {
            FileUploadVisible(true);
            console.log(data);

}

1 个答案:

答案 0 :(得分:1)

我不确定您的问题,但是如果您的服务器返回的数据如下:

04-24 15:22:53.659 16642-16642/? I/art: Late-enabling -Xcheck:jni
04-24 15:22:53.661 16642-16642/? W/art: Unknown instruction set features for ARM CPU variant (generic) using conservative defaults
04-24 15:22:53.709 16642-16649/? I/art: Debugger is no longer active
04-24 15:22:53.709 16642-16649/? I/art: Starting a blocking GC Instrumentation
04-24 15:22:54.610 16642-16642/? W/System: ClassLoader referenced unknown path: /data/app/com.company.androidthings.doorbell-1/lib/arm
04-24 15:22:54.678 16642-16642/com.company.androidthings.doorbell D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
04-24 15:22:54.712 16642-16642/com.company.androidthings.doorbell W/InstanceID/Rpc: Found 10007
04-24 15:22:54.723 16642-16642/com.company.androidthings.doorbell D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell I/FA: App measurement is starting up, version: 9452
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell D/FA: Debug logging enabled
04-24 15:22:54.812 16642-16642/com.company.androidthings.doorbell D/FA: AppMeasurement singleton hash: 202124672
04-24 15:22:54.906 16642-16642/com.company.androidthings.doorbell V/FA: Collection enabled
04-24 15:22:54.907 16642-16642/com.company.androidthings.doorbell V/FA: App package, google app id: com.company.androidthings.doorbell, 1:821276198771:android:044f9c86291658f3
04-24 15:22:54.980 16642-16642/com.company.androidthings.doorbell V/FA: Registered activity lifecycle callback
04-24 15:22:54.986 16642-16642/com.company.androidthings.doorbell I/FirebaseInitProvider: FirebaseApp initialization successful
04-24 15:22:54.989 16642-16642/com.company.androidthings.doorbell I/InstantRun: starting instant run server: is main process
04-24 15:22:55.000 16642-16666/com.company.androidthings.doorbell V/FA: State of service unknown
04-24 15:22:55.000 16642-16666/com.company.androidthings.doorbell V/FA: Checking service availability
04-24 15:22:55.015 16642-16666/com.company.androidthings.doorbell W/GooglePlayServicesUtil: Google Play Store is missing.
04-24 15:22:55.015 16642-16666/com.company.androidthings.doorbell W/FA: Service invalid
04-24 15:22:55.016 16642-16666/com.company.androidthings.doorbell V/FA: Setting useService: false
04-24 15:22:55.019 16642-16666/com.company.androidthings.doorbell V/FA: Using local app measurement service
04-24 15:22:55.449 16642-16642/com.company.androidthings.doorbell V/FA: onActivityCreated
04-24 15:22:55.449 16642-16642/com.company.androidthings.doorbell D/DoorbellActivity: Doorbell Activity created.
04-24 15:22:55.450 16642-16642/com.company.androidthings.doorbell D/DoorbellActivity: No permission
04-24 15:22:55.502 16642-16666/com.company.androidthings.doorbell V/FA: Activity resumed, time: 331914987
04-24 15:22:55.530 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:22:55.563 16642-16642/com.company.androidthings.doorbell V/FA: Bound to IMeasurementService interface
04-24 15:22:55.565 16642-16666/com.company.androidthings.doorbell V/FA: Connected to service
04-24 15:22:55.566 16642-16666/com.company.androidthings.doorbell V/FA: Processing queued up service tasks: 1
04-24 15:22:59.196 16642-16666/com.company.androidthings.doorbell W/art: Long monitor contention with owner pool-2-thread-1 (16678) at long com.android.org.conscrypt.NativeCrypto.RSA_generate_key_ex(int, byte[])(NativeCrypto.java:-2) waiters=0 in java.lang.String com.google.firebase.iid.zzg.get(java.lang.String, java.lang.String) for 3.621s
04-24 15:22:59.236 16642-16666/com.company.androidthings.doorbell I/FA: This instance being marked as an uploader
04-24 15:22:59.696 16642-16666/com.company.androidthings.doorbell D/FA: Unable to get advertising id: com.google.android.gms.common.GooglePlayServicesNotAvailableException: com.google.android.gms.measurement.internal.zzt.zzlx(Unknown Source)
04-24 15:22:59.711 16642-16666/com.company.androidthings.doorbell D/FA: Setting user property: _fot, 1493049600000
04-24 15:22:59.719 16642-16666/com.company.androidthings.doorbell D/FA: User property set: _fot, 1493049600000
04-24 15:22:59.723 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_f,params=Bundle[{_c=1}]
04-24 15:22:59.790 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _f, 22
04-24 15:22:59.792 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_f', params=Bundle[{_c=1, _o=auto}]}
04-24 15:22:59.802 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14436
04-24 15:22:59.807 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 84
04-24 15:22:59.808 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_e,params=Bundle[{_et=1}]
04-24 15:22:59.840 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _e, 23
04-24 15:22:59.841 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_e', params=Bundle[{_o=auto, _et=1}]}
04-24 15:22:59.847 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14390
04-24 15:22:59.853 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 45
04-24 15:23:04.241 16642-16666/com.company.androidthings.doorbell V/FA: Inactivity, disconnecting from AppMeasurementService
04-24 15:23:04.276 16642-16642/com.company.androidthings.doorbell V/FA: onUnbind called for intent. action: com.google.android.gms.measurement.START
04-24 15:23:04.277 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:05.504 16642-16666/com.company.androidthings.doorbell V/FA: Session started, time: 331924989
04-24 15:23:05.550 16642-16666/com.company.androidthings.doorbell I/FA: Tag Manager is not found and thus will not be used
04-24 15:23:05.552 16642-16666/com.company.androidthings.doorbell D/FA: Logging event (FE): _s, Bundle[{_o=auto}]
04-24 15:23:05.555 16642-16666/com.company.androidthings.doorbell V/FA: Using local app measurement service
04-24 15:23:05.562 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:23:05.564 16642-16642/com.company.androidthings.doorbell V/FA: Bound to IMeasurementService interface
04-24 15:23:05.564 16642-16666/com.company.androidthings.doorbell V/FA: Connected to service
04-24 15:23:05.565 16642-16666/com.company.androidthings.doorbell V/FA: Processing queued up service tasks: 1
04-24 15:23:05.572 16642-16666/com.company.androidthings.doorbell V/FA: Logging event: origin=auto,name=_s,params=Bundle[{_o=auto}]
04-24 15:23:05.594 16642-16666/com.company.androidthings.doorbell V/FA: Saving event, name, data size: _s, 14
04-24 15:23:05.596 16642-16666/com.company.androidthings.doorbell V/FA: Event recorded: Event{appId='com.company.androidthings.doorbell', name='_s', params=Bundle[{_o=auto}]}
04-24 15:23:05.655 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 14850
04-24 15:23:05.660 16642-16666/com.company.androidthings.doorbell V/FA: Background event processing time, ms: 89
04-24 15:23:10.577 16642-16666/com.company.androidthings.doorbell V/FA: Inactivity, disconnecting from AppMeasurementService
04-24 15:23:10.616 16642-16642/com.company.androidthings.doorbell V/FA: onUnbind called for intent. action: com.google.android.gms.measurement.START
04-24 15:23:10.618 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:20.547 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementReceiver got: com.google.android.gms.measurement.UPLOAD
04-24 15:23:20.562 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is starting up
04-24 15:23:20.564 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService called. startId, action: 1, com.google.android.gms.measurement.UPLOAD
04-24 15:23:20.588 16642-16666/com.company.androidthings.doorbell V/FA: Fetching remote configuration: com.company.androidthings.doorbell
04-24 15:23:20.598 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService processed last upload request
04-24 15:23:20.598 16642-16642/com.company.androidthings.doorbell V/FA: Local AppMeasurementService is shutting down
04-24 15:23:20.601 16642-17004/com.company.androidthings.doorbell D/NetworkSecurityConfig: No Network Security Config specified, using platform default
04-24 15:23:21.835 16642-16666/com.company.androidthings.doorbell V/FA: Parsed config. version, gmp_app_id: 1492543680583000, 1:821276198771:android:044f9c86291658f3
04-24 15:23:21.841 16642-16666/com.company.androidthings.doorbell V/FA: Successfully fetched config. Got network response. code, size: 200, 52
04-24 15:23:21.892 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _f, 0
04-24 15:23:21.896 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _e, 0
04-24 15:23:21.899 16642-16666/com.company.androidthings.doorbell V/FA: event, affected audience count: _s, 0
04-24 15:23:21.901 16642-16666/com.company.androidthings.doorbell V/FA: property, affected audience count: _fot, 0
04-24 15:23:21.924 16642-16666/com.company.androidthings.doorbell V/FA: Saving bundle, size: 301
04-24 15:23:21.947 16642-16666/com.company.androidthings.doorbell V/FA: Uploading data. app, uncompressed size, data: com.company.androidthings.doorbell, 356, 
                                                                       batch {
                                                                         bundle {
                                                                           protocol_version: 1
                                                                           platform: android
                                                                           gmp_version: 9452
                                                                           uploading_gmp_version: 9452
                                                                           gmp_app_id: 1:821276198771:android:044f9c86291658f3
                                                                           app_id: com.company.androidthings.doorbell
                                                                           app_version: 1.0
                                                                           app_version_major: 1
                                                                           firebase_instance_id: eNnLI0cB484
                                                                           dev_cert_hash: -8029454304837808102
                                                                           app_store: manual_install
                                                                           upload_timestamp_millis: 1493047401878
                                                                           start_timestamp_millis: 1493047379237
                                                                           end_timestamp_millis: 1493047385505
                                                                           app_instance_id: 570e158a1616db1ea428bad0ac67c079
                                                                           os_version: 7.0
                                                                           device_model: iot_rpi3
                                                                           user_default_language: en-us
                                                                           time_zone_offset_minutes: 0
                                                                           bundle_sequential_index: 1
                                                                           service_upload: false
                                                                           user_property {
                                                                             set_timestamp_millis: 1493047379237
                                                                             name: _fot
                                                                             int_value: 1493049600000
                                                                           }
                                                                           event {
                                                                             name: _f
                                                                             timestamp_millis: 1493047379237
                                                                             previous_timestamp_millis: 0
                                                                             param {
                                                                               name: _c
                                                                               int_value: 1
                                                                             }
                                                                             param {
                                                                               name: _o
                                                                               string_value: auto
                                                                             }
                                                                           }
                                                                           event {
                                                                             name: _e
                                                                             timestamp_millis: 1493047379237
                                                                             previous_timestamp_millis: 0
                                                                             param {
                                                                               name: _o
                                                                               string_value: auto
                                                                             }
                                                                             param {
                                                                               name: _et
                                                                               int_value: 1
                                                                             }
                                                                           }
                                                                           event {
                                                                             name: _s
                                                                             timestamp_millis: 1493047385505
                                                                             previous_timestamp_millis: 0
                                                                             param {
                                                                               name: _o
                                                                               string_value: auto
                                                                             }
                                                                           }
                                                                         }
                                                                       }
04-24 15:23:21.950 16642-17004/com.company.androidthings.doorbell V/FA: Uploading data. size: 315
04-24 15:23:22.025 16642-16666/com.company.androidthings.doorbell V/FA: Upload scheduled in approximately ms: 3599959
04-24 15:23:22.030 16642-16666/com.company.androidthings.doorbell V/FA: Successful upload. Got network response. code, size: 204, 0

你可以这样做:

[{"name":"toto.txt", "message":"bla", "success":true},{"name":"titi.txt", "message":"blabla", "success":true}]

或者如果您只想显示成功上传的文件:

success:function(fileList) {
 fileList.forEach(function(file){
   console.log("File name:" + file.name + ", msg:" + file.message + ", success: " + file.success);
 })
}