2013-08-19 81 views
-1

檢索共性與個性元素我有一個JSON在這種格式從JsonArray

[ 
    {"ip":"190","params":{"key":"Thread_State","value":"start"}}, 
    {"ip":"190","params":{"key":"Rate_Classification","value":"30"}}, 
    {"ip":"190","params":{"key":"Rate_Evaluation","value":"30"}}, 
    {"ip":"191","params":{"key":"Thread_State","value":"start"}}, 
    {"ip":"191","params":{"key":"Thread_State","value":"stop"}} 
] 

,我想要從基於鍵和值這個JSON共同和獨特的元素。

例如:

共同要素是{ 「IP」:190 {"key":Thread_State,"value":start}},{ 「IP」:191 {"key":Thread_State,"value":start}}

我們如何使用JavaScript這樣的結果?

+0

其中是json格式??? – 2013-08-19 08:55:18

+0

@kishore這是一組元素?顯示完整的對象。 –

+0

是的,這是一個數組 –

回答

0
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
<script type="text/javascript"> 
var json_string ='[{"ip":"190","params":{"key":"Thread_State","value":"start"}},{"ip":"190","params":{"key":"Rate_Classification","value":"30"}},{"ip":"190","params":{"key":"Rate_Evaluation","value":"30"}},{"ip":"191","params":{"key":"Thread_State","value":"start"}},{"ip":"191","params":{"key":"Thread_State","value":"stop"}}]'; 
var dataArray = []; 
var encoded = jQuery.parseJSON(json_string); 
$.each(encoded, function (index, value) { 
    dataArray.push([value["ip"].toString(), value["params"]["key"], value["params"]["value"] ]); 
}); 
alert(dataArray); 
</script> 
+0

不,這是錯的。請理解我的問題 –

+0

您需要json對象或json格式的值,正如您所寫的那樣。 – 2013-08-19 09:33:50

+0

我需要結果Json –