如何从Json数组中提取数据?

时间:2018-10-12 09:26:48

标签: java json

Json object

我使用 C:\Users\rg\Documents\myReaction\reaction>reaction INFO: Could not find files for the given pattern(s). Setting up plugin imports... Setting up style imports... Provisioning assets... [[[[[ C:\Users\rg\Documents\myReaction\reaction ]]]]] => Started proxy. => Started MongoDB. app/client/plugins.less: warn: There are some @import rules those are not taking effect as they are required to be in the beginning of the file. app/client/plugins.less: warn: There are some @import rules those are not taking effect as they are required to be in the beginning of the file. Building for os.windows.x86_64 \ <--- Last few GCs ---> [4340:000001E838675AB0] 510760 ms: Mark-sweep 1313.1 (1441.7) -> 1313.1 (1441.7) MB, 1340.6 / 0.2 ms allocation failure GC in old space requested [4340:000001E838675AB0] 512026 ms: Mark-sweep 1313.1 (1441.7) -> 1313.1 (1425.2) MB, 1265.4 / 0.3 ms last resort GC in old space requested [4340:000001E838675AB0] 513465 ms: Mark-sweep 1313.1 (1425.2) -> 1313.1 (1425.2) MB, 1439.4 / 0.2 ms last resort GC in old space requested <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 000003BA0CF25879 <JSObject> 0: builtin exit frame: stringify(this=000003BA0CF090A9 <Object map = 0000016865602BA1>,00000321ED7822D1 <undefined>,00000321ED7822D1 <undefined>,00000015838125E1 <JSArray[2]>) 1: arguments adaptor frame: 1->3 2: _linkJS [C:\Users\rg\AppData\Local\.meteor\packages\meteor-tool\1.8.0-rc.14\mt-os.windows.x86_64\tools\isobuild\compiler-plugin.js:~1569] [pc=000003E280B1B649](thi... FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node_module_register 2: v8::internal::FatalProcessOutOfMemory 3: v8::internal::FatalProcessOutOfMemory 4: v8::internal::Factory::NewRawOneByteString 5: v8::internal::Smi::SmiPrint 6: v8::internal::StackGuard::HandleInterrupts 7: v8::internal::wasm::LocalDeclEncoder::Size 8: v8::internal::wasm::LocalDeclEncoder::Size Jsonobject中提取数据并将其存储在对象中:

RawmatrixData

现在我想用一些字符串值替换数据org.json.JSONObject item = Fir.getJSONObject(i); Object value1 = item.get("RawMatrixData")` ,如何实现呢?

我尝试使用342771123181ArrayList<String>

“ LstMatrixFirmInfo”:[       {         “ RawMatrixData”:“ [[342771123181,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null ,null,null,null,null,null,null,null,null,null],[3427714486446,1,2,null,null,null,null,null,null,null,null,null,null,null,null,null,28.99,28.99 ,28.99,25,4.81,4.81,4.81,null,null,null,null,null,null,null,null,null]]]}

1 个答案:

答案 0 :(得分:-1)

RawMatrixData是否应为图像或JSON数组中的字符串。

如果RawMatrixData应该是字符串,则可以转换为JSONArray

我只会使用字符串替换。

String replacedText = Fir.getString('RawMatrixData').replace('342771123181', 'foobar') Fir.push('RawMatrixData', replacedText);

上面的操作可以一行完成,但是为了便于理解却没有。第一行从Json对象获取字符串,然后用foobar替换数字。 然后将文本推回json对象,覆盖旧值。 我相信上面的代码会根据您提供的图片来解决您的问题。

如果RawMatrixData应该是JSON数组而不是字符串,那么在这种情况下,您必须遍历整个数组替换。