-1

この形式のJSONがあります

[
    {"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 を使用してこの結果を取得するにはどうすればよいでしょうか?

4

1 に答える 1

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> 
于 2013-08-19T09:11:25.743 に答える