Javascript / Jquery multidimensional array - arrays
I Have an array like this :
var ProG = [[1,0,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];
I have also a hidden field (id=prog-id) in a form, that I use to send this array to the server:
jQuery('#prog-id').val(JSON.stringify(ProG));
the sent array become:
"prog": "[[1,0,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]"
the next code take the array and other data from the server with ajax request:
value is the data that come from ajax
I create an object:
var obj = jQuery.parseJSON(value);
Now the problem:
if I console.log(ProG) the array before sent I get:
Array[7]0: Array[4]1: Array[4]2: Array[4]3: Array[4]4: Array[4]5: Array[4]6: Array[4]length: 7__proto__: Array[0]
that is ok.
But If I do the same after getting array I receive this:
[[1,0,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
How can I put the received array in original format?
Ok I find out:
jQuery.parseJSON(ProG).
Related
inserting json object into already existing json object inside of a json array
lets say I have a json array called arr, which contains some number of json objects, jsobj1, jsboj2,... jsbojn. if I want to add a new json object jsobjm inside of jsobj2 how would I do that? I tried to do arr.get(1).put("jsobjm", jsobjm), but I get the error cannot find symbol, pointing to the . before the put().
Well you could do this (instead of manipulating the array as a String): Convert the JSON array into it's object equivalent and add the object you want using the programming language you use. Convert the object back to JSON eg using Javascript let arr = '[{\"name\":\"Ford\"}]'; //convert to object let objArray = JSON.parse(arr); let obj = objArray[0]; //add the other object you want into the first object obj.description = {"reason":"My fav car"}; console.log(obj); //convert everything back to string console.log(JSON.stringify(obj)); JSfiddle: https://jsfiddle.net/allkenang/tuvxrgj3/8/
How to loop SOAP request with values received from a response array
I am making a SOAP request, and I am receiving the response that's returned as an array: - [print] [ "M4205N", "M4206U" ] For each item in the array, I want to make another SOAP request. I've read how you can do this with tables and call a feature file, and I've read how to loop through an array, and call a js function. I cannot figure out how to loop through the array, and pass each value to another SOAP request XML (one at a time). I want to do something like this: Given soapURL And method post def responseArray = /xml path for the codes I want/ def result = call read('otherRequest.feature') responseArray The otherRequest.feature file would look something like this: #ignore Feature: Background: * def myNewRequest = read('soap.xml') Scenario: Given soapURL * replace myNewRequest | token | value | | ##refNum## | responseArrayValue | When request myNewRequest And method post However, I get this error: GetNewMessageList.feature:27 - argument not json or map for feature call loop array position: 0, M4205N How can I loop through each item in the array, and pass each value to the other feature file?
The addition of this one line should do what you want. Yes there is a hard requirement that the "loop" array should be an array of JSON objects. But you can convert an array of primitives in one step: * def responseArray = karate.mapWithKey(responseArray, 'responseArrayValue') This is documented here: https://github.com/intuit/karate#json-transforms
how get all id from json to array on other variables - jmeter
I have two JSON. In the both I have name. How can I get names from first JSON and add to array? Later I want do this same with second JSON later i want both array compare? How can I do this? jsonArray1 = [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}]; jsonArray2 = [{'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}]; for example I want: a = [doug, dofug] b = [goud, doaaug] and later check if these are the same arrays i don't know how can i do this in jmeter, help
To convert one array to another: Add JSR223 PostProcessor as a child of the request which returns first JSON Array Put the following code into "Script" area: def builder = new groovy.json.JsonBuilder() builder(com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(),'$..name').collect()) vars.put('array1', builder.toPrettyString()) That's it, you should be able to access the newly generated JSON Array as ${array1} where required Repeat the same steps for the second JSON array. There are several options on how to compare 2 JSON entities, depending on what you're trying to achieve you can go for: Response Assertion a JSR223 Assertion and a 3rd-party library like: Jackson Gson JSONassert
Qooxdoo/JSON Array undefined value
I'm working in order to connect my client to my server (node.js). I use this code : var storeEmployees = new qx.data.store.Json("Load/Infos"); qx.event.Registration.addListener(storeEmployees, "loaded", function(){ var model = this.getModel(); console.log(model.getRecords()); console.log(model.getTotal()); console.log(model.getStatus()); }, storeEmployees); My server send this value : {records: ["bonjour", "aurevoir"], total:2, status:"success"} however the "console.log(model.getRecords())" write on the console : Object[undefined, undefined] Instead of Object["bonjour","aurevoir"] Values for "getTotal" and "getStatus" are good. The problem is only for the array (simple array and complexe array). Any idea ? Thanks in advance !
The store marshals the data to model objects. This means that you are dealing with qx.data.Array here which unfortunately can not be accessed vie brackets notation (e.g. Data[0]). But this is what the console does. For debugging and logging you can access the plain array with the .toArray() method which then will show the results.
Is it possible to store an Array into an EncryptedLocalStore item? AIR
I want to save my Array's strucure and load it the next time I open my AIR application. Is there a way to store it to an EncryptedLocalStore item then get it later when I re-open the app?
EncryptedLocalStore.setItem() method takes a byte array when storing contents. To store an array, just use ByteArray.writeObject() method (as described in http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html#writeObject()) to convert your Array to a ByteArray - and then persist the same to the ELS. var array:Array = getArray(); var byteArray:ByteArray = new ByteArray(); byteArray.writeObject(array); EncryptedLocalStore.setItem('somekey', byteArray); Hope this helps. Update: Added code to retrieve the array back. var byteArray:ByteArray = EncryptedLocalStore.getItem('somekey'); var array:Array = byteArray.readObject() as Array; Update: For custom classes. In case you want to serialize your own custom classes to the ByteArray, you may have to call registerClassAlias() before writing the object to the ByteArray. For eg. registerClassAlias("com.example.eg", ExampleClass);
I have found that it is easiest to to serialize the Array to a string and then store that string in the ELS. Then when you pull it out deserialize it back into an Array.