-4

Please help me for How to convert data from {"rOjbectId":["abc","def",ghi","ghikk"]} to "["abc", "def", "ghi", "ghikk"] using ajax

BobbyTables
  • 4,481
  • 1
  • 31
  • 39

3 Answers3

0

Is this in javascript? Then you access the property:

var obj = {"rOjbectId":["abc","def","ghi","ghikk"]}
console.log(obj.rOjbectId)
BobbyTables
  • 4,481
  • 1
  • 31
  • 39
  • Thanks for your quick response Zedd, but i need to convert json to array as shown above : from {"rOjbectId":["abc","def",ghi","ghikk"]} to "["abc", "def", "ghi", "ghikk"] – satyanarayana banisetti Sep 15 '15 at 07:44
  • {"rOjbectId":["abc","def","ghi","ghikk"]} is dynamic value , it will be change as user request and need response json object to array ["abc", "def", "ghi", "ghikk"] – satyanarayana banisetti Sep 15 '15 at 07:47
  • well, my response shows how to do this. Your get the array if you access the rOjbectId property of your ajax response – BobbyTables Sep 15 '15 at 07:55
0

Assuming in javascript you need to access the property of your object. In this case obj.rOjbectId, or you can access it like this too: obj['rOjbectId']

Corbin
  • 414
  • 5
  • 19
0
dictionary = {"cats":[1,2,37,38,40,32,33,35,39,36], "dogs": [4,5,6,3,2]};
var k= Object.keys(dictionary);

then loop over k for different keys and you may get the vals like this

dictionary[k[0]]

part of solution taken from here.Hope it helps

Community
  • 1
  • 1
Aameer
  • 1,366
  • 1
  • 11
  • 30
  • $(function() { var result=[]; $.ajax({ url: "http://localhost:8080/World/hello?name="+$("#tags").val(), success: function( data, textStatus, jqXHR) { alert(data); var availableTags=["abc", "def", "ghi", "ghikk"]; $.each(availableTags, function( key, value ) { result.push(value); }); } }); $("#tags").autocomplete({ source: result }); }); – satyanarayana banisetti Sep 15 '15 at 08:08
  • here availableTags[] is hard coded to ["abc", "def", "ghi", "ghikk"] , but same data is avilable in "data" as shown in alert in the form of " {"rOjbectId":["abc","def",ghi","ghikk"]} " i have to pass same data to result[]. Please suggest me which one is better. – satyanarayana banisetti Sep 15 '15 at 08:08
  • @satyanarayanabanisetti I am not sure what you are trying to achieve.But from what I understand this would be a different question.Moreover you want to know which one is better with what are you comparing this one? – Aameer Sep 15 '15 at 08:29